android - Unable to instantiate PlayersActivity NullPointerException error -


my playersactivity class working fine until today when mysteriously stopped. think have problem listview can't quite figure out have changed although did make list view different class. can't quite figure out i'm going wrong

public class playersactivity extends listactivity { private static final int activity_create=0; private static final int activity_edit=1;  private static final int insert_id = menu.first; private static final int delete_id = menu.first + 1;  private playerdbadapter mdbhelper;  private simplecursoradapter playerlist; listview list = getlistview();  /** called when activity first created. */ @override public void oncreate(bundle savedinstancestate) {      super.oncreate(savedinstancestate);     setcontentview(r.layout.playerdata);       mdbhelper = new playerdbadapter(this);     mdbhelper.open();     filldata();     registerforcontextmenu(getlistview()); }  private void filldata() {     cursor players = mdbhelper.fetchallplayers();     startmanagingcursor(players);      // create array specify fields want display in list (only title)     string[] = new string[]{playerdbadapter.key_title,playerdbadapter.key_body, playerdbadapter.key_number, playerdbadapter.key_team};       // , array of fields want bind fields (in case text1)     int[] = new int[]{r.id.pposition,r.id.pname,r.id.pnumber,r.id.pteam};      // create simple cursor adapter , set display      playerlist = new simplecursoradapter(this, r.layout.playerinfo , players, from, to);     list.setadapter(playerlist);     playerlist.notifydatasetchanged();     list.setonitemclicklistener(new onitemclicklistener() {            public void onitemclick(adapterview<?> listview, view view,               int position, long id) {            cursor cursor = (cursor) listview.getitematposition(position);               string playername =              cursor.getstring(cursor.getcolumnindexorthrow("player_name"));            toast.maketext(getapplicationcontext(),              playername, toast.length_short).show();             }       });      edittext myfilter = (edittext) findviewbyid(r.id.myfilter);     myfilter.addtextchangedlistener(new textwatcher() {       public void aftertextchanged(editable s) {      }       public void beforetextchanged(charsequence s, int start,         int count, int after) {      }       public void ontextchanged(charsequence s, int start,         int before, int count) {       playerlist.getfilter().filter(s.tostring());      }     });      playerlist.setfilterqueryprovider(new filterqueryprovider() {            public cursor runquery(charsequence constraint) {                return mdbhelper.fetchplayersbyname(constraint.tostring());            }        });     } 

logcat

`e/androidruntime(341): fatal exception: main  e/androidruntime(341): java.lang.runtimeexception: unable instantiate activity componentinfo{your.dissertation.project/your.dissertation.project.playersactivity}: java.lang.nullpointerexception 04-18 18:15:08.619: e/androidruntime(341):  @ android.app.activitythread.performlaunchactivity(activitythread.java:1544) 04-18 18:15:08.619: e/androidruntime(341):  @ android.app.activitythread.handlelaunchactivity(activitythread.java:1638) 04-18 18:15:08.619: e/androidruntime(341):  @ android.app.activitythread.access$1500(activitythread.java:117) 04-18 18:15:08.619: e/androidruntime(341):  @ android.app.activitythread$h.handlemessage(activitythread.java:928) 04-18 18:15:08.619: e/androidruntime(341):  @ android.os.handler.dispatchmessage(handler.java:99) 04-18 18:15:08.619: e/androidruntime(341):  @ android.os.looper.loop(looper.java:123) 04-18 18:15:08.619: e/androidruntime(341):  @ android.app.activitythread.main(activitythread.java:3647) 04-18 18:15:08.619: e/androidruntime(341):  @ java.lang.reflect.method.invokenative(native method) 04-18 18:15:08.619: e/androidruntime(341):  @ java.lang.reflect.method.invoke(method.java:507) 04-18 18:15:08.619: e/androidruntime(341):  @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:839) 04-18 18:15:08.619: e/androidruntime(341):  @ com.android.internal.os.zygoteinit.main(zygoteinit.java:597) 04-18 18:15:08.619: e/androidruntime(341):  @ dalvik.system.nativestart.main(native method) 04-18 18:15:08.619: e/androidruntime(341): caused by: java.lang.nullpointerexception 04-18 18:15:08.619: e/androidruntime(341):  @ android.app.activity.setcontentview(activity.java:1657) 04-18 18:15:08.619: e/androidruntime(341):  @ android.app.listactivity.ensurelist(listactivity.java:312) 04-18 18:15:08.619: e/androidruntime(341):  @ android.app.listactivity.getlistview(listactivity.java:297) 04-18 18:15:08.619: e/androidruntime(341):  @ your.dissertation.project.playersactivity.<init>(playersactivity.java:35) 04-18 18:15:08.619: e/androidruntime(341):  @ java.lang.class.newinstanceimpl(native method) 04-18 18:15:08.619: e/androidruntime(341):  @ java.lang.class.newinstance(class.java:1409) 04-18 18:15:08.619: e/androidruntime(341):  @ android.app.instrumentation.newactivity(instrumentation.java:1021) 04-18 18:15:08.619: e/androidruntime(341):  @ android.app.activitythread.performlaunchactivity(activitythread.java:1536) 04-18 18:15:08.619: e/androidruntime(341):  ... 11 more ` 

you're calling

 listview list = getlistview(); 

outside of app's lifecycle. move initialization oncreate() method. (and/or post code line, crashing app, if logcat correct)...


Comments

Popular posts from this blog

node.js - Bad Request - node js ajax post -

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -