sqlite - Android - CursorIndexOutOfBounds Index 0 requested with size of 0 -
i'm trying return values sqlite database code through use of cursor
06-14 22:31:30.586: e/androidruntime(18859): android.database.cursorindexoutofboundsexception: index 0 requested, size of 0 06-14 22:31:30.586: e/androidruntime(18859): @ android.database.abstractcursor.checkposition(abstractcursor.java:426) 06-14 22:31:30.586: e/androidruntime(18859): @ android.database.abstractwindowedcursor.checkposition(abstractwindowedcursor.java:136) 06-14 22:31:30.586: e/androidruntime(18859): @ android.database.abstractwindowedcursor.getint(abstractwindowedcursor.java:68) 06-14 22:31:30.586: e/androidruntime(18859): @ com.km.parkit.chosenslotdao.cursortoslot(chosenslotdao.java:166) 06-14 22:31:30.586: e/androidruntime(18859): @ com.km.parkit.chosenslotdao.createslot(chosenslotdao.java:57) 06-14 22:31:30.586: e/androidruntime(18859): @ com.km.parkit.mainmap$1.onclick(mainmap.java:80) 06-14 22:31:30.586: e/androidruntime(18859): @ android.view.view.performclick(view.java:4756) 06-14 22:31:30.586: e/androidruntime(18859): @ android.view.view$performclick.run(view.java:19761)
i have each , every 1 of column using separate get
this
public string getselectedslot() { string slot = new string(); cursor cursor = database.query(chosenslotdatabasehandler.table_chosen_parking_slot, chosenslotcolumn, null, null, null, null, null); if( cursor.movetofirst() ) { slot = cursor.getstring(0); } // make sure close cursor cursor.close(); return slot; } public string getparked() { string parked = new string(); cursor cursor = database.query(chosenslotdatabasehandler.table_chosen_parking_slot, chosenparkedcolumn, null, null, null, null, null); if( cursor.movetofirst() ) { parked = cursor.getstring(0); } // make sure close cursor cursor.close(); return parked; } public string getisparked() { string isparked = new string(); cursor cursor = database.query(chosenslotdatabasehandler.table_chosen_parking_slot, isparkedcolumn, null, null, null, null, null); if( cursor.movetofirst() ) { isparked = cursor.getstring(0); } // make sure close cursor cursor.close(); return isparked; }
and here's updateslot
public chosenparkingslot updateslot(string id, string selectedslot, string parkedrow, string isparked) { contentvalues values = new contentvalues(); values.put(chosenslotdatabasehandler.chosen_id, id); values.put(chosenslotdatabasehandler.chosen_slot_name, selectedslot); values.put(chosenslotdatabasehandler.chosen_parked_row, parkedrow); values.put(chosenslotdatabasehandler.is_parked, isparked); long insertid = database.update(chosenslotdatabasehandler.table_chosen_parking_slot, values, "_id= " + id, null); cursor cursor = database.query(chosenslotdatabasehandler.table_chosen_parking_slot, allcolumns, chosenslotdatabasehandler.chosen_id + " = " + insertid, null, null, null, null); cursor.movetofirst(); chosenparkingslot newslot = cursortoslot(cursor); cursor.close(); return newslot; }
here's cursor
private chosenparkingslot cursortoslot(cursor cursor) { chosenparkingslot parkingslot = new chosenparkingslot(); parkingslot.setid(cursor.getint(0)); parkingslot.setslotname(cursor.getstring(1)); parkingslot.setparkedrow(cursor.getstring(2)); parkingslot.setisparked(cursor.getint(3)); return parkingslot; }
what went wrong?? index 0 means first column.. right....?
i did create database values of id = 1
, slot_name = selectedslot
rest null.
first check condition before fetching data
if(cursor!=null && cursor.getcount()>0){ cursor.movetofirst(); num = cursor.getstring(cursor.getcolumnindex("<column index>")); }
maybe cursor object isn't fetching database.
follow stackoverflow link android.database.cursorindexoutofboundsexception: index 0 requested, size of 0
Comments
Post a Comment