Listview error

Asked

Viewed 50 times

0

Good afternoon, I have an error that came up after having edited a function to save data by Dialogfragment, in logCat presents the error that and my Listview is null, only that I can not take the null from the class because it will not recognize:

follow the Logcat below:

E/AndroidRuntime: FATAL EXCEPTION: main
                  Process: com.allsport.miyonic.allsport, PID: 2933
                  java.lang.RuntimeException: Unable to resume activity {com.allsport.miyonic.allsport/com.allsport.miyonic.allsport.ResultSimples}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.ListView.setAdapter(android.widget.ListAdapter)' on a null object reference
                      at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3103)
                      at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3134)
                      at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2481)
                      at android.app.ActivityThread.-wrap11(ActivityThread.java)
                      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
                      at android.os.Handler.dispatchMessage(Handler.java:102)
                      at android.os.Looper.loop(Looper.java:148)
                      at android.app.ActivityThread.main(ActivityThread.java:5417)
                      at java.lang.reflect.Method.invoke(Native Method)
                      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
                      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
                   Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.ListView.setAdapter(android.widget.ListAdapter)' on a null object reference
                      at com.allsport.miyonic.allsport.ResultSimples.onResume(ResultSimples.java:51)
                      at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1258)
                      at android.app.Activity.performResume(Activity.java:6312)
                      at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3092)
                      at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3134) 
                      at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2481) 
                      at android.app.ActivityThread.-wrap11(ActivityThread.java) 
                      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) 
                      at android.os.Handler.dispatchMessage(Handler.java:102) 
                      at android.os.Looper.loop(Looper.java:148) 
                      at android.app.ActivityThread.main(ActivityThread.java:5417) 
                      at java.lang.reflect.Method.invoke(Native Method) 
                      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
                      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 

Java code of the result Activity:

package com.allsport.miyonic.allsport;

import android.content.pm.ActivityInfo;
import android.os.PersistableBundle;
import android.support.v7.app.AppCompatActivity;
        import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
        import android.widget.ArrayAdapter;
        import android.widget.Button;
        import android.widget.ListView;
import android.widget.TextView;

import java.util.List;

        import Base.DbHelper;
        import Base.Esporte;

        import static android.os.FileObserver.DELETE;

public class ResultSimples extends AppCompatActivity {

    private ListView lista;

    @Override
    public void onCreate(Bundle savedInstanceState, PersistableBundle persistentState) {
        super.onCreate(savedInstanceState, persistentState);
        setContentView(R.layout.activity_result_simples);
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

        lista = (ListView) findViewById(R.id.ListaTimes);

        /*apagar.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                DbHelper dd = new DbHelper(ResultSimples.this);
                dd.delete(); // É necessário passar o parâmetro
            }
        });*/
    }

    @Override
    public void onResume(){
        super.onResume();

        DbHelper dbhe = new DbHelper(this);
        List<Esporte> listaResultPartida = dbhe.selectTodosResult();
        ArrayAdapter<Esporte> adp = new ArrayAdapter<Esporte>(this, R.layout.resultado_modificado, android.R.id.text1, listaResultPartida);

        lista.setAdapter(adp);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.resultado_menu, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {

        int id = item.getItemId();

        if (id == R.id.deletar) {
        }

        return super.onOptionsItemSelected(item);
    }
}

Code of the Dialogfragment :

package com.allsport.miyonic.allsport;


import android.app.Dialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.app.DialogFragment;
import android.support.v7.app.AlertDialog;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.EditText;

import Base.Esporte;

public class DialogGol extends DialogFragment{

    private EditText caixa;

    @NonNull
    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState){

        View vi = LayoutInflater.from(getContext()).inflate(R.layout.caixa_jogador_dialog, null);
        caixa = (EditText) vi.findViewById(R.id.caixa_dialog_1);

        AlertDialog.Builder bir = new AlertDialog.Builder(getActivity());

        bir.setMessage("Gol de ").setPositiveButton("Confirmar", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {

                Esporte inseri = new Esporte();
                inseri.setjogadores(caixa.getText().toString());


            }
        }).setNegativeButton("Cancelar", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                //nulo
            }
        });

        bir.setTitle("Gooolll!!!");

        View view = LayoutInflater.from(getContext()).inflate(R.layout.caixa_jogador_dialog, null);
        bir.setView(view);

        AlertDialog dialog = bir.create();

        return dialog;
    }

}

XML Activity Result:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                xmlns:tools="http://schemas.android.com/tools"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:paddingBottom="@dimen/activity_vertical_margin"
                android:paddingLeft="@dimen/activity_horizontal_margin"
                android:paddingRight="@dimen/activity_horizontal_margin"
                android:paddingTop="@dimen/activity_vertical_margin"
                tools:context="com.allsport.miyonic.allsport.ResultSimples"
                android:background="#003366">

    <TextView
    android:text="Resultado das Partidas"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true"
        android:id="@+id/textView"
    android:textColor="#fff"
    android:textStyle="normal|italic"
    android:textAlignment="center"
    android:textSize="29dp" />

    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_marginBottom="15px">

    </LinearLayout>

    <ListView
    android:layout_width="match_parent"
        android:id="@+id/ListaTimes"
    android:textColor="@color/corList"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_marginTop="150px"
        android:layout_height="match_parent" />

</RelativeLayout>

Thank you...

  • Where your R.layout.activity_result_simple?

  • I edited the question put the xml of activity_result_simple and it is in the Resultsimple class

  • Try placing the list = (Listview) findViewById(R.id.Listtimes); at the beginning of your onResume

  • @seamusd worked not...

  • how to connect the dialog with Activity and the list?

  • @Mr_anderson The confirm button saves the name String in the bank... the list had created another because I had to customize it (color) and Activity would be where it loads the database array inside the listview.

Show 1 more comment
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.