java - android.database.CursorIndexOutOfBoundsException....crash report -
i crash report error app. use imported sqlite database in assets folder. doing wrong? here's error user crash report:
android.database.cursorindexoutofboundsexception: index 0 requested, size of 0 @ android.database.abstractcursor.checkposition(abstractcursor.java:418) @ android.database.abstractwindowedcursor.checkposition(abstractwindowedcursor.java:136) @ android.database.abstractwindowedcursor.getstring(abstractwindowedcursor.java:50) @ rs.androidaplikacije.zastaveigradovi.kviz20hard.nextquestiongrad(kviz20hard.java:328) @ rs.androidaplikacije.zastaveigradovi.kviz20hard.access$1(kviz20hard.java:307) @ rs.androidaplikacije.zastaveigradovi.kviz20hard$2.run(kviz20hard.java:68) @ android.os.handler.handlecallback(handler.java:615) @ android.os.handler.dispatchmessage(handler.java:92) @ android.os.looper.loop(looper.java:137) @ android.app.activitythread.main(activitythread.java:4921) @ java.lang.reflect.method.invokenative(native method) @ java.lang.reflect.method.invoke(method.java:511) @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:1038) @ com.android.internal.os.zygoteinit.main(zygoteinit.java:805) @ dalvik.system.nativestart.main(native method)
and here's question method game class:
private void nextquestiongrad() { flag.setvisibility(view.gone); dodatnopitanje.setvisibility(view.visible); testadapter mdbhelper = new testadapter(this); databasehelper mydbhelper = new databasehelper(this); if(!mydbhelper.checkdatabase()){ mdbhelper.createdatabase(); } try{ mdbhelper.open(); cursor c = mdbhelper.gettestdatagradovi(mcurrentid); c.movetofirst(); list<answer> labels = new arraylist<answer>(); labels.add(new answer(c.getstring(2), true)); labels.add(new answer(c.getstring(3), false)); labels.add(new answer(c.getstring(4), false)); labels.add(new answer(c.getstring(5), false)); tacanodg = c.getstring(2); collections.shuffle(labels); dodatnopitanje.settext(c.getstring(1)); bodgovor1.settext(labels.get(0).option); bodgovor1.settag(labels.get(0)); bodgovor1.setonclicklistener(clicklistenergrad); bodgovor2.settext(labels.get(1).option); bodgovor2.settag(labels.get(1)); bodgovor2.setonclicklistener(clicklistenergrad); bodgovor3.settext(labels.get(2).option); bodgovor3.settag(labels.get(2)); bodgovor3.setonclicklistener(clicklistenergrad); bodgovor4.settext(labels.get(3).option); bodgovor4.settag(labels.get(3)); bodgovor4.setonclicklistener(clicklistenergrad); score.settext("score: " + brojactacnihodgovora); } finally{ mdbhelper.close(); } }
i error on line:
labels.add(new answer(c.getstring(2), true));
here's adapter class:
public class testadapter { protected static final string tag = "dataadapter"; private final context mcontext; private sqlitedatabase mdb; private databasehelper mdbhelper; public testadapter(context context) { this.mcontext = context; mdbhelper = new databasehelper(mcontext); } public testadapter createdatabase() throws sqlexception { try { mdbhelper.createdatabase(); } catch (ioexception mioexception) { log.e(tag, mioexception.tostring() + " unabletocreatedatabase"); throw new error("unabletocreatedatabase"); } return this; } public testadapter open() throws sqlexception { try { mdbhelper.opendatabase(); mdbhelper.close(); mdb = mdbhelper.getreadabledatabase(); } catch (sqlexception msqlexception) { log.e(tag, "open >>"+ msqlexception.tostring()); throw msqlexception; } return this; } public void close() { mdbhelper.close(); } public cursor gettestdata(string whereclause){ string sql ="select * tblpitanja 1 = 1 " + whereclause + " order random() limit 1"; return mdb.rawquery(sql, null); } public cursor gettestdatagradovi(long id){ string sql ="select * tblgradovi _id = " + id; return mdb.rawquery(sql, null); } public cursor gettestdatavalute(long id){ string sql ="select * tblvalute _id = " + id; return mdb.rawquery(sql, null); } }
you trying access cursor
data seems empty. use c.movetofirst()
check if cursor empty - returns boolean indication: boolean isfilledwithdata = c.movetofirst()
Comments
Post a Comment