I have setup a SQLite database in my android application. I used a tutorial from google and my database works (I can put data in it and read it out in an other form). Now, I want to get the column price and put it in a graph. I can draw the graph already with hard coded values. I’m trying:
Cursor item0 = _dbHelper.fetcAllBoughtItems();
startManagingCursor(item0);
String xaxis[]=new String[4];
xaxis[0]= item0.getString(item0.getColumnIndexOrThrow(databaseManager.KEY_BOUGHT_ITEM));
xaxis[1]="2007";
xaxis[2]="2008";
xaxis[3]="2009";
I get the follow error (I know it’s telling me what’s wrong, but I can’t get it fixed)
04-27 10:03:21.382: ERROR/AndroidRuntime(6920): java.lang.RuntimeException: Unable to start activity ComponentInfo{Adforce.files/Adforce.files.summarySpendBudget}: android.database.CursorIndexOutOfBoundsException: Index -1 requested, with a size of 5
Can someone help me please?
Regards
Edit:
fetchAllBoughtItems() code is:
public Cursor fetchAllBoughtItems(){ //function to fetch all bought items
return mDb.query(DATABASE_TABLE_ItemB, new String[]{KEY_ROWID_ItemB, KEY_BOUGHT_ITEM, KEY_PRICE_ItemB }, null, null, null, null, null);
}
fetcAllBoughtItems() returns Cursor without column named databaseManager.KEY_BOUGHT_ITEM
fix fetcAllBoughtItems()
EDIT:
add
item0.moveToFirst()beforeitem0.getString(...and check if will return true