java - Android application fetch data from SQLite -
i new android programming , trying fetch data sqlite , display in list view. getting , displaying data
datahandler handler=new datahandler (getbasecontext()); handler.open(); cursor c=handler.returndata_schedule(); list<scheduledata> arr=new arraylist<scheduledata>(); if(c.movetofirst()){ do{ string date=c.getstring(0); string time=c.getstring(1); string food=c.getstring(2); scheduledata mydata=new scheduledata(date,time,food); arr.add(mydata); }while(c.movetonext()); } scheduleadapter myadapter=new scheduleadapter(this,r.layout.schedule_list,arr); listview listview=(listview)findviewbyid(r.id.listview1); listview.setadapter(myadapter);
this fetch function.
public cursor returndata_schedule() { return db.query(table_schedule,new string[] {date,time,food},null,null,null,null,null); }
this adapter class
public class scheduleadapter extends arrayadapter<scheduledata> { context mycontext; int layout; list<scheduledata> obj; public scheduleadapter(context context, int resource,list<scheduledata> arr) { super(context, resource, arr); mycontext=context; layout=resource; obj=arr; } @override public view getview(int position, view convertview,viewgroup parent){ view row; if(convertview==null){ layoutinflater inflater=((activity) mycontext).getlayoutinflater(); row=inflater.inflate(layout,parent,false); } else{ row=(view)convertview; } textview datetext=(textview)row.findviewbyid(r.id.textview1); textview timetext=(textview)row.findviewbyid(r.id.textview2); textview foodtext=(textview)row.findviewbyid(r.id.textview3); datetext.settext(obj.get(position).getdate()); timetext.settext(obj.get(position).gettime()); foodtext.settext(obj.get(position).getfood()); return row; } }
this logcat
03-25 16:43:38.330: d/dalvikvm(1789): gc_for_alloc freed 93k, 6% free 3118k/3288k, paused 267ms, total 280ms 03-25 16:43:38.450: i/dalvikvm-heap(1789): grow heap (frag case) 3.723mb 635812-byte allocation 03-25 16:43:38.620: d/dalvikvm(1789): gc_for_alloc freed 9k, 5% free 3729k/3912k, paused 167ms, total 167ms 03-25 16:43:39.420: e/sqlitelog(1789): (1) near "from": syntax error 03-25 16:43:39.450: d/androidruntime(1789): shutting down vm 03-25 16:43:39.450: w/dalvikvm(1789): threadid=1: thread exiting uncaught exception (group=0xb3aa6ba8) 03-25 16:43:39.620: e/androidruntime(1789): fatal exception: main 03-25 16:43:39.620: e/androidruntime(1789): process: com.example.slimart, pid: 1789 03-25 16:43:39.620: e/androidruntime(1789): java.lang.runtimeexception: unable start activity componentinfo{com.example.slimart/com.example.slimart.seeschedule}: android.database.sqlite.sqliteexception: near "from": syntax error (code 1): , while compiling: select 1, 12, schedule 03-25 16:43:39.620: e/androidruntime(1789): @ android.app.activitythread.performlaunchactivity(activitythread.java:2195) 03-25 16:43:39.620: e/androidruntime(1789): @ android.app.activitythread.handlelaunchactivity(activitythread.java:2245) 03-25 16:43:39.620: e/androidruntime(1789): @ android.app.activitythread.access$800(activitythread.java:135) 03-25 16:43:39.620: e/androidruntime(1789): @ android.app.activitythread$h.handlemessage(activitythread.java:1196) 03-25 16:43:39.620: e/androidruntime(1789): @ android.os.handler.dispatchmessage(handler.java:102) 03-25 16:43:39.620: e/androidruntime(1789): @ android.os.looper.loop(looper.java:136) 03-25 16:43:39.620: e/androidruntime(1789): @ android.app.activitythread.main(activitythread.java:5017) 03-25 16:43:39.620: e/androidruntime(1789): @ java.lang.reflect.method.invokenative(native method) 03-25 16:43:39.620: e/androidruntime(1789): @ java.lang.reflect.method.invoke(method.java:515) 03-25 16:43:39.620: e/androidruntime(1789): @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:779) 03-25 16:43:39.620: e/androidruntime(1789): @ com.android.internal.os.zygoteinit.main(zygoteinit.java:595) 03-25 16:43:39.620: e/androidruntime(1789): @ dalvik.system.nativestart.main(native method) 03-25 16:43:39.620: e/androidruntime(1789): caused by: android.database.sqlite.sqliteexception: near "from": syntax error (code 1): , while compiling: select 1, 12, schedule 03-25 16:43:39.620: e/androidruntime(1789): @ android.database.sqlite.sqliteconnection.nativepreparestatement(native method) 03-25 16:43:39.620: e/androidruntime(1789): @ android.database.sqlite.sqliteconnection.acquirepreparedstatement(sqliteconnection.java:889) 03-25 16:43:39.620: e/androidruntime(1789): @ android.database.sqlite.sqliteconnection.prepare(sqliteconnection.java:500) 03-25 16:43:39.620: e/androidruntime(1789): @ android.database.sqlite.sqlitesession.prepare(sqlitesession.java:588) 03-25 16:43:39.620: e/androidruntime(1789): @ android.database.sqlite.sqliteprogram.<init>(sqliteprogram.java:58) 03-25 16:43:39.620: e/androidruntime(1789): @ android.database.sqlite.sqlitequery.<init>(sqlitequery.java:37) 03-25 16:43:39.620: e/androidruntime(1789): @ android.database.sqlite.sqlitedirectcursordriver.query(sqlitedirectcursordriver.java:44) 03-25 16:43:39.620: e/androidruntime(1789): @ android.database.sqlite.sqlitedatabase.rawquerywithfactory(sqlitedatabase.java:1314) 03-25 16:43:39.620: e/androidruntime(1789): @ android.database.sqlite.sqlitedatabase.querywithfactory(sqlitedatabase.java:1161) 03-25 16:43:39.620: e/androidruntime(1789): @ android.database.sqlite.sqlitedatabase.query(sqlitedatabase.java:1032) 03-25 16:43:39.620: e/androidruntime(1789): @ android.database.sqlite.sqlitedatabase.query(sqlitedatabase.java:1200) 03-25 16:43:39.620: e/androidruntime(1789): @ com.example.slimart.datahandler.returndata_schedule(datahandler.java:103) 03-25 16:43:39.620: e/androidruntime(1789): @ com.example.slimart.seeschedule.oncreate(seeschedule.java:20) 03-25 16:43:39.620: e/androidruntime(1789): @ android.app.activity.performcreate(activity.java:5231) 03-25 16:43:39.620: e/androidruntime(1789): @ android.app.instrumentation.callactivityoncreate(instrumentation.java:1087) 03-25 16:43:39.620: e/androidruntime(1789): @ android.app.activitythread.performlaunchactivity(activitythread.java:2159) 03-25 16:43:39.620: e/androidruntime(1789): ... 11 more 03-25 16:43:43.720: i/process(1789): sending signal. pid: 1789 sig: 9 03-25 16:43:46.350: d/gralloc_goldfish(1818): emulator without gpu emulation detected.
i have no idea why crashes. have used same method fetch data other table , gives me correct data. not know know syntax error talking in 03-25 16:43:39.420: e/sqlitelog(1789): (1) near "from": syntax error
please guys tell me how solve issue. in advance.
return db.query(table_schedule,new string[] {date,time,food},null,null,null,null,null);
in here data,time,food
ought column names , not values. syntax error when food
empty string.
i don't know table schema, guessing column names, should read:
return db.query(table_schedule,new string[] {"date","time","food"},null,null,null,null,null);
with column names quoted strings.
Comments
Post a Comment