java - NullPointerException Error stopping listview -


hello trying populate list view sqlite database. im using custom cursor class adapt data , inflate layout

    public customcursoradapter(context context, cursor c) {     super(context, c);   }  @override public view newview(context context, cursor cursor, viewgroup parent) {     // when view created first time,     // need tell adapters, how each item     layoutinflater inflater = layoutinflater.from(parent.getcontext());     view retview = inflater.inflate(r.layout.suspect_list, parent, false);      return retview; }  @override public void bindview(view view, context context, cursor cursor) {     // here setting our data     // means, take data cursor , put in views      textview textviewid = (textview) view.findviewbyid(r.id.suspect_id);     textviewid.settext(cursor.getstring(cursor.getcolumnindex(cursor.getcolumnname(0))));      textview textviewpersonname = (textview) view.findviewbyid(r.id.suspect_name);     textviewpersonname.settext(cursor.getstring(cursor.getcolumnindex(cursor.getcolumnname(1))));      textview textviewpersonsex = (textview) view.findviewbyid(r.id.suspect_sex);     textviewpersonsex.settext(cursor.getstring(cursor.getcolumnindex(cursor.getcolumnname(2))));  } 

upon running code error shown through logcat

    05-04 15:10:05.371: d/androidruntime(444): shutting down vm 05-04 15:10:05.371: w/dalvikvm(444): threadid=1: thread exiting uncaught exception (group=0x40015560) 05-04 15:10:05.381: e/androidruntime(444): fatal exception: main 05-04 15:10:05.381: e/androidruntime(444): java.lang.runtimeexception: unable start activity componentinfo{com.example.sherlock/com.example.sherlock.suspectview}: java.lang.nullpointerexception 05-04 15:10:05.381: e/androidruntime(444):  @ android.app.activitythread.performlaunchactivity(activitythread.java:1647) 05-04 15:10:05.381: e/androidruntime(444):  @ android.app.activitythread.handlelaunchactivity(activitythread.java:1663) 05-04 15:10:05.381: e/androidruntime(444):  @ android.app.activitythread.access$1500(activitythread.java:117) 05-04 15:10:05.381: e/androidruntime(444):  @ android.app.activitythread$h.handlemessage(activitythread.java:931) 05-04 15:10:05.381: e/androidruntime(444):  @ android.os.handler.dispatchmessage(handler.java:99) 05-04 15:10:05.381: e/androidruntime(444):  @ android.os.looper.loop(looper.java:123) 05-04 15:10:05.381: e/androidruntime(444):  @ android.app.activitythread.main(activitythread.java:3683) 05-04 15:10:05.381: e/androidruntime(444):  @ java.lang.reflect.method.invokenative(native method) 05-04 15:10:05.381: e/androidruntime(444):  @ java.lang.reflect.method.invoke(method.java:507) 05-04 15:10:05.381: e/androidruntime(444):  @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:839) 05-04 15:10:05.381: e/androidruntime(444):  @ com.android.internal.os.zygoteinit.main(zygoteinit.java:597) 05-04 15:10:05.381: e/androidruntime(444):  @ dalvik.system.nativestart.main(native method) 05-04 15:10:05.381: e/androidruntime(444): caused by: java.lang.nullpointerexception 05-04 15:10:05.381: e/androidruntime(444):  @ com.example.sherlock.suspectview.oncreate(suspectview.java:22) 05-04 15:10:05.381: e/androidruntime(444):  @ android.app.instrumentation.callactivityoncreate(instrumentation.java:1047) 05-04 15:10:05.381: e/androidruntime(444):  @ android.app.activitythread.performlaunchactivity(activitythread.java:1611) 05-04 15:10:05.381: e/androidruntime(444):  ... 11 more 

i understand error contracted through misinterpretation of varibles cant see in code going wrong ...

database cursor

public cursor getall() {     string selectquery = "select  * " + table_suspects;     sqlitedatabase db = this.getreadabledatabase();     cursor cursor = db.rawquery(selectquery, null);     return cursor; } 

the activity adapter being used

 databasehandler db = new databasehandler(this);       list = (listview) findviewbyid(r.id.list);       cursor c = db.getall();       customcursoradapter adapter = new customcursoradapter(this, c);       list.setadapter(adapter); 

any help/insight can provide helpful

change

findviewbyid(r.id.list); 

to

findviewbyid(android.r.id.list); 

you need add android namespace since isn't id created


Comments

Popular posts from this blog

Perl - how to grep a block of text from a file -

delphi - How to remove all the grips on a coolbar if I have several coolbands? -

javascript - Animating array of divs; only the final element is modified -