Show information in activity androd studio

1

I am taking a screen "Notification" in the application but will only show the database information without notifying the user. But the information is not showing on the screen, is giving the application stopped.

Class:

import static com.example.tcc.tcc.ResultadoONGActivity.lerListViewId;

public class Notificacao extends AppCompatActivity {

    public static NotificacoesEncontradas notificacaoStatica;
    TextView NotONG;
    private ListView listView;
    notificacoesEncontradasAdapter notificacoesEncontradasAdapter;

    ArrayList id_user = new ArrayList();

    public static String lerListViewIdUser;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_notificacao);

        NotONG = (TextView) findViewById(R.id.NotNaoEncontradas);
        NotONG.setVisibility(View.INVISIBLE);

        Boolean TemDado = BuscarContas();
        if (TemDado == false) {
            NotONG.setVisibility(View.VISIBLE);
            //Toast.makeText(this, "Nenhuma Conta Encontrada", Toast.LENGTH_SHORT).show();

        }

        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                ///de acordo com o "position" irá ler as variaveis atuais abaixo: ///
                lerListViewIdUser = id_user.get(position).toString();
            }
        });
        /*
        Boolean TemDado = VisualizarNotificacoes();
        if (TemDado == false) {
            NotONG.setVisibility(View.VISIBLE);
            //Toast.makeText(this, "Nenhuma Conta Encontrada", Toast.LENGTH_SHORT).show();

        }*/

    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {// esse metodo que manda na action bar
        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.menu_tela_inicial, menu);

        return super.onCreateOptionsMenu(menu);
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_close) {
            //ao clicar em sair irá sair do aplicativo, apenas o finish irá sair apenas da tela atual e não do aplicativo.
            startActivity(new Intent(this,MainActivity.class));
            finish();
            return true;

        }if (id ==R.id.action_perfil){
            startActivity(new Intent(Notificacao.this,EditarPerfilActivity.class));
        }if (id==R.id.action_alterar_senha){
            startActivity(new Intent(Notificacao.this,AlterarSenhaActivity.class));
        }if(id==R.id.action_notificacoes){
            startActivity(new Intent(Notificacao.this,Notificacao.class));
        }if(id==R.id.logo_maos){
            startActivity(new Intent(this, TelaInicialActivity.class));
        }
        return super.onOptionsItemSelected(item);
    }

    public Boolean BuscarContas() {

        ArrayList<NotificacoesEncontradas> fim = new ArrayList<NotificacoesEncontradas>();
        Boolean TemDado = false;
        try {

            String retorno = new HTTPService("notificacoes", "telefone=" + lerListViewIdUser).execute().get();


            JSONArray json = new JSONArray(retorno);

            for(int i = 0; i< json.length();i++){
               NotificacoesEncontradas NotificacoesEncontradas = new NotificacoesEncontradas();

                //atividadesEncontradas.setId_user(json.getJSONObject(i).getString("razao_social"));
                NotificacoesEncontradas.setTelefone(json.getJSONObject(i).getString("telefone"));
                NotificacoesEncontradas.setTipo(json.getJSONObject(i).getString("tipo"));
               // NotificacoesEncontradas.setArea_interesse(json.getJSONObject(i).getString("conta"));



                TemDado = true;
                fim.add(NotificacoesEncontradas);
            }

            carregaResultadoLista(fim);
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        } catch (JSONException e) {
            e.printStackTrace();
        }
        return TemDado;
    }

    public void carregaResultadoLista(ArrayList<NotificacoesEncontradas> lista){
        notificacoesEncontradasAdapter = new notificacoesEncontradasAdapter(Notificacao.this, lista);
        listView.setAdapter(notificacoesEncontradasAdapter);//preenchido dinamicamente
    }
}

Php:

<?php
    include_once 'includes/conexao.php';

    /* check connection */
    if(mysqli_connect_errno()){
        printf("Connect failed: %s\n", mysqli_connect_error());
        exit();
    }

    $user_id = $_GET["user_id"];

    if($user_id != ""){
        // $dbcon->query("SET NAMES 'utf8'");
        $sql    = "SELECT id,
                        user_id,
                        ong_id,
                        tipo_id,
                        tipo,
                        descricao,
                        telefone,
                        visualizada,
                        data_criacao
                    FROM app.notificacao
                    WHERE user_id = '$user_id'
                        AND tipo = 'InteresseObjeto'
                    ORDER BY data_criacao DESC";

        $result = $dbcon->query($sql);

        while($e = mysqli_fetch_assoc($result)){
            $output[] = $e; 
        }   

        print(json_encode($output)); 
        $dbcon->close();
    }
?>

logcat:

  

I / AndroidRuntime: FATAL EXCEPTION: main                     Process: com.example.tcc.tcc PID: 32315                     java.lang.RuntimeException: Unable to start ComponentInfo activity com.example.tcc.tcc {/} com.example.tcc.tcc.Notificacao:   java.lang.NullPointerException: Attempt to invoke virtual method 'void   android.view.View.setVisibility (int) 'on a null object reference                         at android.app.ActivityThread.performLaunchActivity (ActivityThread.java:2984)                         at android.app.ActivityThread.handleLaunchActivity (ActivityThread.java:3045)                         at android.app.ActivityThread.-wrap14 (ActivityThread.java)                         android.app.ActivityThread at $ H.handleMessage (ActivityThread.java:1642)                         at android.os.Handler.dispatchMessage (Handler.java:102)                         at android.os.Looper.loop (Looper.java:154)                         at android.app.ActivityThread.main (ActivityThread.java:6776)                         at java.lang.reflect.Method.invoke (Native Method)                         com.android.internal.os.ZygoteInit at $ MethodAndArgsCaller.run (ZygoteInit.java:1496)                         at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1386)                      Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.View.setVisibility void (int)'   on a null object reference                         at com.example.tcc.tcc.Notificacao.onCreate (Notificacao.java:35)                         at android.app.Activity.performCreate (Activity.java:6955)                         at android.app.Instrumentation.callActivityOnCreate (Instrumentation.java:1126)                         at android.app.ActivityThread.performLaunchActivity (ActivityThread.java:2927)                         at android.app.ActivityThread.handleLaunchActivity (ActivityThread.java:3045)                         at android.app.ActivityThread.-wrap14 (ActivityThread.java)                         android.app.ActivityThread at $ H.handleMessage (ActivityThread.java:1642)                         at android.os.Handler.dispatchMessage (Handler.java:102)                         at android.os.Looper.loop (Looper.java:154)                         at android.app.ActivityThread.main (ActivityThread.java:6776)                         at java.lang.reflect.Method.invoke (Native Method)                         com.android.internal.os.ZygoteInit at $ MethodAndArgsCaller.run (ZygoteInit.java:1496)                         at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1386)

    
asked by anonymous 31.05.2018 / 21:40

1 answer

1
___ erkimt ___ Show information in activity androd studio ______ qstntxt ___

I am taking a screen "Notification" in the application but will only show the database information without notifying the user. But the information is not showing on the screen, is giving the application stopped.

Class:

%pre%

Php:

%pre%

logcat:

  

I / AndroidRuntime: FATAL EXCEPTION: main                     Process: com.example.tcc.tcc PID: 32315                     java.lang.RuntimeException: Unable to start ComponentInfo activity com.example.tcc.tcc {/} com.example.tcc.tcc.Notificacao:   java.lang.NullPointerException: Attempt to invoke virtual method 'void   android.view.View.setVisibility (int) 'on a null object reference                         at android.app.ActivityThread.performLaunchActivity (ActivityThread.java:2984)                         at android.app.ActivityThread.handleLaunchActivity (ActivityThread.java:3045)                         at android.app.ActivityThread.-wrap14 (ActivityThread.java)                         android.app.ActivityThread at $ H.handleMessage (ActivityThread.java:1642)                         at android.os.Handler.dispatchMessage (Handler.java:102)                         at android.os.Looper.loop (Looper.java:154)                         at android.app.ActivityThread.main (ActivityThread.java:6776)                         at java.lang.reflect.Method.invoke (Native Method)                         com.android.internal.os.ZygoteInit at $ MethodAndArgsCaller.run (ZygoteInit.java:1496)                         at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1386)                      Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.View.setVisibility void (int)'   on a null object reference                         at com.example.tcc.tcc.Notificacao.onCreate (Notificacao.java:35)                         at android.app.Activity.performCreate (Activity.java:6955)                         at android.app.Instrumentation.callActivityOnCreate (Instrumentation.java:1126)                         at android.app.ActivityThread.performLaunchActivity (ActivityThread.java:2927)                         at android.app.ActivityThread.handleLaunchActivity (ActivityThread.java:3045)                         at android.app.ActivityThread.-wrap14 (ActivityThread.java)                         android.app.ActivityThread at $ H.handleMessage (ActivityThread.java:1642)                         at android.os.Handler.dispatchMessage (Handler.java:102)                         at android.os.Looper.loop (Looper.java:154)                         at android.app.ActivityThread.main (ActivityThread.java:6776)                         at java.lang.reflect.Method.invoke (Native Method)                         com.android.internal.os.ZygoteInit at $ MethodAndArgsCaller.run (ZygoteInit.java:1496)                         at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1386)

    
______ ___ azszpr303622

Your TextView NotONG = (TextView) findViewById(R.id.NotNaoEncontradas); is not being found in the layout R.layout.activity_notificacao

Make sure that it is set the correct layout or if there is a TextView in layout

    
___
01.06.2018 / 15:33