3
我有一個由sqlite數據庫來源的列表視圖。我在幾個不同的點調用fillData()來更新列表視圖。關閉從未明確呼籲
private void fillData() {
mDbHelper.open();
Cursor c = mDbHelper.fetchAllNotes(table, columns, selection, selectionArgs, null, null);
startManagingCursor(c);
String[] from = new String[] { "quantity", "color", "style" };
int[] to = new int[] { R.id.textQuantity, R.id.textColor, R.id.textStyle };
setListAdapter(new SimpleCursorAdapter(this, R.layout.recordrow, c, from, to) {
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View v = super.getView(position, convertView, parent);
return v;
}
});
}
這有效......問題是,當我打開/關閉/跳轉活動,我得到logcat錯誤。它不會使程序崩潰。的錯誤是:
請確定您明確調用close()上的光標
和
close()方法從未被明確要求在數據庫
所以下});如果我把mDbHelper.close()它崩潰說數據庫沒有打開。如果我把c.close(),我的列表視圖永遠不會填充。我試圖把它們放在其他地方,它給我錯誤說光標/數據庫已經關閉。有什麼想法做什麼?
僅供參考,startManagingCursor方法已棄用。你可能想刪除它,然後在})之後放置mDbHelper.close()。 – chaitanya 2011-04-18 19:36:06
如果我這樣做,列表視圖會填充,但我會得到幾個'正在完成尚未停用或關閉的遊標'錯誤。 – Roger 2011-04-18 19:41:57