it’s me once more, having problems with sqlite for Android
I currently get a “CursorIndexOutOfBoundsException: Index 1 requested, with a size of 1″
However, I had this exception with Index -1 then inserted a cursor.moveToFirst(), then I had this with index 0 , then did cursor.moveToNext();
What I wanna do with my code? I want the information of a selected item (that’s why the selectionArgs are there with sQueryid. What am I doing wrong?
Cursor c = a.managedQuery(uri,
projection, //projection
"_ID=?", //selection string
new String[]{sQueryid}, //selection args array of strings
DepotTableMetaData.DEFAULT_SORT_ORDER); //sort order
c.moveToFirst();
c.moveToNext();
int iqrcode = c.getColumnIndex(ContentProviderMetaData.DepotTableMetaData.ITEM_QRCODE);
int iname = c.getColumnIndex(ContentProviderMetaData.DepotTableMetaData.ITEM_NAME);
int iamount = c.getColumnIndex(ContentProviderMetaData.DepotTableMetaData.ITEM_AMOUNT);
int iunit = c.getColumnIndex(ContentProviderMetaData.DepotTableMetaData.ITEM_UNIT);
int ippu = c.getColumnIndex(ContentProviderMetaData.DepotTableMetaData.ITEM_PPU);
int itotal = c.getColumnIndex(ContentProviderMetaData.DepotTableMetaData.ITEM_TOTAL);
int icomment = c.getColumnIndex(ContentProviderMetaData.DepotTableMetaData.ITEM_COMMENT);
//Gather values
String id = c.getString(Integer.parseInt(queryid.toString()));
String name = c.getString(iname);
String amount = c.getString(iamount);
String unit = c.getString(iunit);
String ppu = c.getString(ippu);
String total = c.getString(itotal);
String comment = c.getString(icomment);
String qrcode = c.getString(iqrcode);
String[] info = new String[]{id,name,amount,unit,ppu,total,comment,qrcode};
moveToFirsttakes you to the first (and only) result. The next call tomoveToNexttakes you to the second result (index 1) which doesn’t exist.Try removing the
c.moveToNext();