CursorIndexOutOfBoundsException while querying SQLite in Android code -
kindly note trying retrieve values table in sqlite db in android app, on button click event , present through listview.i able insert records table on same event.although throws following error:
`05-15 11:54:16.721: w/system.err(1834): android.database.cursorindexoutofboundsexception: index 1 requested, size of 1 05-15 11:54:16.721: w/system.err(1834): @ android.database.abstractcursor.checkposition(abstractcursor.java:434) 05-15 11:54:16.721: w/system.err(1834): @ android.database.abstractwindowedcursor.checkposition(abstractwindowedcursor.java:136) 05-15 11:54:16.721: w/system.err(1834): @ android.database.abstractwindowedcursor.getstring(abstractwindowedcursor.java:50) `
follwing chunk of code using insert,retrieve , display records table in listview:
save.setonclicklistener(new view.onclicklistener() { public void onclick(view v) { event=spinner.getselecteditem().tostring(); message=ed1.gettext().tostring(); mainactivity.mydatabase.opendatabase("/data/data/org.mithil.appname/databases/tablename", null,mainactivity.mydatabase.open_readwrite); mainactivity.mydatabase.execsql("insert " + mainactivity.tablename + " values ('"+ finalnumber +"','"+ name +"','"+ message +"','"+ event +"','"+ ldate +"');"); cursor cu = mainactivity.mydatabase.rawquery("select name " + mainactivity.tablename + " date =" + ldate +";" , null); cu.movetofirst(); log.d("first rec", cu.tostring()); while(cu!=null) { try{ lstitem.add(cu.getstring(0)); cu.movetonext(); } catch(exception e) { e.printstacktrace(); } }
all happening in button click.the insertions getting reflected in table 'select' not.i reckon wrong moving cursor.the table consist of 5 fields off want retrieve 1 ie. 'name' field , add name listview.kindly correct me going wrong.thanks lot.
while(cu !isafterlast()){...
shouldn't go out of bounds then. can not-null , still go out of bounds.
Comments
Post a Comment