writing data from sqlite database android -
writing data from sqlite database android -
i want read info sqlite database in android app app forcibly shuts down.
public void getdata(string[] results) { string[] columns = new string[]{ key_sno,key_item,key_price,key_time }; cursor c = canteendb.query(database_ctable,columns,null,null,null,null,null); int isno = c.getcolumnindex(key_sno); int iitem = c.getcolumnindex(key_item); int iprice = c.getcolumnindex(key_price); int itime = c.getcolumnindex(key_time); for(c.movetofirst(); !c.isafterlast(); c.movetonext()) { results[0]=c.getstring(isno); results[1]=c.getstring(iitem); results[2]=c.getstring(iprice); results[3]=c.getstring(itime); } }
here's logcat:
06-21 18:55:17.028: e/androidruntime(9160): fatal exception: main 06-21 18:55:17.028: e/androidruntime(9160): java.lang.runtimeexception: unable start activity componentinfo{com.example.expenditurelogs/com.example.expenditurelogs.canteenlog}: java.lang.nullpointerexception 06-21 18:55:17.028: e/androidruntime(9160): @ android.app.activitythread.performlaunchactivity(activitythread.java:2245) 06-21 18:55:17.028: e/androidruntime(9160): @ android.app.activitythread.handlelaunchactivity(activitythread.java:2299) 06-21 18:55:17.028: e/androidruntime(9160): @ android.app.activitythread.access$700(activitythread.java:150) 06-21 18:55:17.028: e/androidruntime(9160): @ android.app.activitythread$h.handlemessage(activitythread.java:1280) 06-21 18:55:17.028: e/androidruntime(9160): @ android.os.handler.dispatchmessage(handler.java:99) 06-21 18:55:17.028: e/androidruntime(9160): @ android.os.looper.loop(looper.java:137) 06-21 18:55:17.028: e/androidruntime(9160): @ android.app.activitythread.main(activitythread.java:5283) 06-21 18:55:17.028: e/androidruntime(9160): @ java.lang.reflect.method.invokenative(native method) 06-21 18:55:17.028: e/androidruntime(9160): @ java.lang.reflect.method.invoke(method.java:511) 06-21 18:55:17.028: e/androidruntime(9160): @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:1102) 06-21 18:55:17.028: e/androidruntime(9160): @ com.android.internal.os.zygoteinit.main(zygoteinit.java:869) 06-21 18:55:17.028: e/androidruntime(9160): @ dalvik.system.nativestart.main(native method) 06-21 18:55:17.028: e/androidruntime(9160): caused by: java.lang.nullpointerexception 06-21 18:55:17.028: e/androidruntime(9160): @ com.example.expenditurelogs.ctable.getdata(ctable.java:78) 06-21 18:55:17.028: e/androidruntime(9160): @ com.example.expenditurelogs.canteenlog.oncreate(canteenlog.java:22) 06-21 18:55:17.028: e/androidruntime(9160): @ android.app.activity.performcreate(activity.java:5283) 06-21 18:55:17.028: e/androidruntime(9160): @ android.app.instrumentation.callactivityoncreate(instrumentation.java:1097) 06-21 18:55:17.028: e/androidruntime(9160): @ android.app.activitythread.performlaunchactivity(activitythread.java:2209) 06-21 18:55:17.028: e/androidruntime(9160): ... 11 more
i think need open database first , utilize cursor c;
db.open();
cursor c = canteendb.query(database_ctable,columns,null,null,null,null,null);
android sqlite
Comments
Post a Comment