Tuesday, 15 September 2015

java - Null Pointer Exception Sql Database -



java - Null Pointer Exception Sql Database -

hey if want start activity got these exception

06-23 19:07:44.022: e/androidruntime(1271): fatal exception: main 06-23 19:07:44.022: e/androidruntime(1271): process: food.manager, pid: 1271 06-23 19:07:44.022: e/androidruntime(1271): java.lang.runtimeexception: unable start activity componentinfo{food.manager/food.manager.verlaufessen}: java.lang.nullpointerexception 06-23 19:07:44.022: e/androidruntime(1271): @ .app.activitythread.performlaunchactivity(activitythread.java:2596) 06-23 19:07:44.022: e/androidruntime(1271): @ android.app.activitythread.handlelaunchactivity(activitythread.java:2653) 06-23 19:07:44.022: e/androidruntime(1271): @ android.app.activitythread.access$800(activitythread.java:156) 06-23 19:07:44.022: e/androidruntime(1271): @ android.app.activitythread$h.handlemessage(activitythread.java:1355) 06-23 19:07:44.022: e/androidruntime(1271): @ android.os.handler.dispatchmessage(handler.java:102) 06-23 19:07:44.022: e/androidruntime(1271): @ android.os.looper.loop(looper.java:157) 06-23 19:07:44.022: e/androidruntime(1271): @ android.app.activitythread.main(activitythread.java:5872) 06-23 19:07:44.022: e/androidruntime(1271): @ java.lang.reflect.method.invokenative(native method) 06-23 19:07:44.022: e/androidruntime(1271): @ java.lang.reflect.method.invoke(method.java:515) 06-23 19:07:44.022: e/androidruntime(1271): @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:858) 06-23 19:07:44.022: e/androidruntime(1271): @ com.android.internal.os.zygoteinit.main(zygoteinit.java:674) 06-23 19:07:44.022: e/androidruntime(1271): @ dalvik.system.nativestart.main(native method) 06-23 19:07:44.022: e/androidruntime(1271): caused by: java.lang.nullpointerexception 06-23 19:07:44.022: e/androidruntime(1271): @ food.manager.verlaufessen.populatelistviewfromdb(verlaufessen.java:99) 06-23 19:07:44.022: e/androidruntime(1271): @ food.manager.verlaufessen.oncreate(verlaufessen.java:40) 06-23 19:07:44.022: e/androidruntime(1271): @ android.app.activity.performcreate(activity.java:5312) 06-23 19:07:44.022: e/androidruntime(1271): @ android.app.instrumentation.callactivityoncreate(instrumentation.java:1111) 06-23 19:07:44.022: e/androidruntime(1271): @ android.app.activitythread.performlaunchactivity(activitythread.java:2552) 06-23 19:07:44.022: e/androidruntime(1271): ... 11 more

i want open on create mode sql database

public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_verlauf_essen); getactionbar().setdisplayhomeasupenabled(true); appcontext = getapplicationcontext(); opendb();

thanks help:) open method:

mydb = new dbadapter(this); mydb.open();

my database adapter:

public dbadapter(context ctx) { this.context = ctx; mydbhelper = new databasehelper(context); } // open database connection. public dbadapter open() { db = mydbhelper.getwritabledatabase(); homecoming this; } // close database connection. public void close() { mydbhelper.close(); }

this pupulate method

private void populatelistviewfromdb() { cursor cursor = mydb.getallrows(); // allow activity manage lifetime of cursor. // deprecated! runs on ui thread, ok small/short queries. startmanagingcursor(cursor); // setup mapping cursor view fields: string[] fromfieldnames = new string[] {dbadapter.key_kalo, dbadapter.key_hydrate, dbadapter.key_fat, dbadapter.key_protein ,dbadapter.key_cal}; int[] toviewids = new int[] {r.id.item_kalorien, r.id.item_kg_in_g, r.id.item_f_in_g, r.id.item_p_in_g,r.id.item_cal}; // create adapter may columns of db onto elemesnt in ui. simplecursoradapter mycursoradapter = new simplecursoradapter( this, // context r.layout.item_tagebuch, // row layout template cursor, // cursor (set of db records map) fromfieldnames, // db column names toviewids // view ids set info in ); // set adapter list view listview mylist = (listview) findviewbyid(r.id.listviewtagebuch); mylist.setadapter(mycursoradapter);

getallrows method>

public cursor getallrows() { string = null; cursor c = db.query(true, database_table, all_keys, where, null, null, null, null, null); if (c != null) { c.movetofirst(); } homecoming c; }

java android database sqlite

No comments:

Post a Comment