我在Android应用程序中设置了一个SQLite数据库。我使用谷歌的教程和我的数据库工作(我可以将数据放入其中并以其他形式读出)。现在,我想获得列价并将其放入图表中。我可以使用硬编码值绘制图形。我在尝试:
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";
我得到了跟随错误(我知道它告诉我什么是错的,但我无法解决它)
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
是的,有人能帮帮我吗?
此致
修改
fetchAllBoughtItems()代码是:
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);
}
答案 0 :(得分:1)
fetcAllBoughtItems()返回没有名为databaseManager.KEY_BOUGHT_ITEM的列的Cursor
修复fetcAllBoughtItems()
修改强>
在item0.moveToFirst()
之前添加item0.getString(...
并检查是否会返回true