上下文:我可以使用public Cursor getEntry(long rowId)
和public Cursor getEntry(String category)
等其他方法检索条目,但出于某种原因,public Cursor getAllEntries()
不起作用。我收到错误Cursor - Invalid statement in fillWindow()
代码:
//---retrieves all entries---
public Cursor getAllEntries() throws SQLException
{
Log.d(BudgetConstants.DEBUG_TAG, "DBAdapter - DatabaseHelper - getAllEntries();");
return db.query(DATABASE_TABLE,
new String[] {
KEY_ROWID,
KEY_TYPE,
KEY_DATE,
KEY_CATEGORY,
KEY_AMOUNT},
null, null, null, null, null);
}
完整代码:
ListActivity(从我调用数据库的地方) - http://pastebin.com/UGSvhsfd
DBAdapter(我的数据库接口) - http://pastebin.com/jqtLiPHB
DBAdapter(我的朋友DBAdapter可以正常工作) - http://pastebin.com/QTRF958d
EDIT1 : 调用db的代码:
private void updateGUI(int displayScope) {
Cursor c;
ArrayList<Entry> entries; // NOTE: making an Entry ArrayList due to the fact that rows in Cursors cannot be deleted
switch(displayScope) {
case BudgetConstants.DISPLAY_ALL:
c = getAllTransactions();
//boolean b = c.moveToFirst();
//Log.d(BudgetConstants.DEBUG_TAG, "movetofirst: "+b);
entries = extractEntries(c, BudgetConstants.FILTER_LIMIT_ALL);
displayEntries(entries);
break;
case BudgetConstants.DISPLAY_MONTH:
c = getAllTransactions();
entries = extractEntries(c, BudgetConstants.FILTER_LIMIT_MONTH);
displayEntries(entries);
break;
}
}
private ArrayList<Entry> extractEntries(Cursor c, int filter) {
ArrayList<Entry> res = new ArrayList<Entry>();
Calendar cal = Calendar.getInstance();
int currMonth = cal.get(Calendar.MONTH)+1;
int currYear = cal.get(Calendar.YEAR);
if (c.moveToFirst()) { // <------ getting an error here: Cursor - Invalid statement in fillWindow()
do {
if (filter==BudgetConstants.FILTER_LIMIT_MONTH) {
String entryDate = c.getString(BudgetConstants.DB_DATE);
int entryMonth = getMonth(entryDate);
int entryYear = getYear(entryDate);
if (!((entryMonth==currMonth) && (entryYear==currYear)))
continue;
} else if (filter==BudgetConstants.FILTER_LIMIT_ALL)
res.add(new Entry(c.getString(BudgetConstants.DB_DATE), c.getString(BudgetConstants.DB_TYPE), c.getString(BudgetConstants.DB_AMOUNT)));
} while (c.moveToNext());
}
return res;
}
答案 0 :(得分:0)
将db.close();
移至private void displayEntries(ArrayList<Entry> entries)
的最后一行,似乎就是这样做了。