I’m trying to take an entire column from a table in my DB and store all the entries into a String array Below you have my code:
public Cursor fetchAllBarcodeEntries(){
return db.query(BARCODE_TABLE, new String[] {KEY_BARCODE_ID, KEY_BARCODE_NUMBER, KEY_BARCODE_PRODUCT, KEY_BARCODE_PRODUCT_DESC}, null, null, null, null, null);
}
I’m calling and using the function like this:
Cursor c = dbAdapter.fetchAllBarcodeEntries();
for(int i = 0; i < c.getCount(); i++){
stringArray[i] = c.getString(c.getColumnIndex(dbAdapter.KEY_BARCODE_PRODUCT);
}
This is part of the error log that I’m getting
01-26 23:15:02.434: E/AndroidRuntime(787): Caused by: android.database.CursorIndexOutOfBoundsException: Index -1 requested, with a size of 1
Any help would this would be greatly appreciated…
The answer is here
Afterwards you can convert the ArrayList into a String array: