android - Couldn't read row 1, col -1 from CursorWindow -
i have following error message in application:
05-13 09:05:53.218: e/androidruntime(5339): fatal exception: main 05-13 09:05:53.218: e/androidruntime(5339): java.lang.runtimeexception: unable start activity componentinfo{com.example.unserekinder/com.example.unserekinder.ereignisse}: java.lang.illegalstateexception: couldn't read row 1, col -1 cursorwindow. make sure cursor initialized correctly before accessing data it. 05-13 09:05:53.218: e/androidruntime(5339): @ android.app.activitythread.performlaunchactivity(activitythread.java:2180) 05-13 09:05:53.218: e/androidruntime(5339): @ android.app.activitythread.handlelaunchactivity(activitythread.java:2230) 05-13 09:05:53.218: e/androidruntime(5339): @ android.app.activitythread.access$600(activitythread.java:141) 05-13 09:05:53.218: e/androidruntime(5339): @ android.app.activitythread$h.handlemessage(activitythread.java:1234) 05-13 09:05:53.218: e/androidruntime(5339): @ android.os.handler.dispatchmessage(handler.java:99) 05-13 09:05:53.218: e/androidruntime(5339): @ android.os.looper.loop(looper.java:137) 05-13 09:05:53.218: e/androidruntime(5339): @ android.app.activitythread.main(activitythread.java:5041) 05-13 09:05:53.218: e/androidruntime(5339): @ java.lang.reflect.method.invokenative(native method) 05-13 09:05:53.218: e/androidruntime(5339): @ java.lang.reflect.method.invoke(method.java:511) 05-13 09:05:53.218: e/androidruntime(5339): @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:793) 05-13 09:05:53.218: e/androidruntime(5339): @ com.android.internal.os.zygoteinit.main(zygoteinit.java:560) 05-13 09:05:53.218: e/androidruntime(5339): @ dalvik.system.nativestart.main(native method) 05-13 09:05:53.218: e/androidruntime(5339): caused by: java.lang.illegalstateexception: couldn't read row 1, col -1 cursorwindow. make sure cursor initialized correctly before accessing data it. 05-13 09:05:53.218: e/androidruntime(5339): @ android.database.cursorwindow.nativegetstring(native method) 05-13 09:05:53.218: e/androidruntime(5339): @ android.database.cursorwindow.getstring(cursorwindow.java:434) 05-13 09:05:53.218: e/androidruntime(5339): @ android.database.abstractwindowedcursor.getstring(abstractwindowedcursor.java:51) 05-13 09:05:53.218: e/androidruntime(5339): @ com.example.unserekinder.ereignisse.datenfuerlistviewereignis(ereignisse.java:49) 05-13 09:05:53.218: e/androidruntime(5339): @ com.example.unserekinder.ereignisse.oncreate(ereignisse.java:28) 05-13 09:05:53.218: e/androidruntime(5339): @ android.app.activity.performcreate(activity.java:5104) 05-13 09:05:53.218: e/androidruntime(5339): @ android.app.instrumentation.callactivityoncreate(instrumentation.java:1080) 05-13 09:05:53.218: e/androidruntime(5339): @ android.app.activitythread.performlaunchactivity(activitythread.java:2144) 05-13 09:05:53.218: e/androidruntime(5339): ... 11 more
my table looks this:
public static final string ereignisid = "id"; public static final string table_name_ereignis="ereignis"; public static final string ereignisname = "ereignisname"; public static final string ereigniszeit = "ereigniszeit"; public static final string ereignisgenaueres = "ereignisgenaueres"; public static final string kindid = "kindid"; private static final string table_ereignis_create = "create table if not exists " + table_name_ereignis + " (" + ereignisid + " integer primary key autoincrement, " + ereignisname + " text, " + ereigniszeit + " text, " + ereignisgenaueres + " text, " + kindid + " integer, foreign key (" + kindid + ") references " + table_name_kind + "(" + id + "));";
this function error happens:
private arraylist<ereignis> datenfuerlistviewereignis(){ dbhelper db = new dbhelper(this); arraylist<ereignis> arr = new arraylist<ereignis>(); listview lv = (listview) findviewbyid(r.id.lvereignisse); id = getintent().getintextra("kinderid", 0); system.out.println("ssssssssssssssssssssssssssssssssssssss" + id); cursor c = db.selectereignis(id); c.movetofirst(); int count = c.getcount(); int = 0; while(c.movetonext()) { // here happens error! arr.add(new ereignis(c.getstring(c.getcolumnindex("ereigniszeit")), c.getstring(c.getcolumnindex("ereignisname")) )); i++; } if(arr.size() > 0){ return arr; } else{ arraylist<ereignis> arrempty = new arraylist<ereignis>(); arrempty.add(new ereignis("keine daten vorhanden", " ")); return arrempty; } }
can tell me mistake is??
edit:
this selectereignis()
public cursor selectereignis(int kindid){ sqlitedatabase db = getreadabledatabase(); cursor cursor = db.rawquery("select ereignisname ereignis kindid = " + kindid, null); system.out.println("hallliiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii" + cursor.getcount()); return cursor; }
cursor cursor = db.rawquery("select ereignisname ereignis kindid = " + kindid, null);
change
cursor cursor = db.rawquery("select ereignisname, ereigniszeit ereignis kindid = " + kindid, null);
do if table , query fine.
if(c.movetofirst()) { { // array stuff here }while(c.movetonext()); }
Comments
Post a Comment