我在我的 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(){//获取所有已购买元素的函数
返回 mDb.query(DATABASE_TABLE_ItemB, new String[]{KEY_ROWID_ItemB, KEY_BOUGHT_ITEM, KEY_PRICE_ItemB }, null, null, null, null, null);
}
最佳答案
fetcAllBoughtItems() 返回没有名为 databaseManager.KEY_BOUGHT_ITEM 的列的 Cursor
修复 fetcAllBoughtItems()
编辑:
在 item0.getString(...
之前添加 item0.moveToFirst()
并检查是否会返回 true
关于android - 从数据库中获取图形 Android 的数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5801112/