[英]The cursor should be freed up after use with #close
我正在將此代碼用於 Android,但是當我調試時,我看到了這個錯誤: the cursor should be freed up after use with #close
此行有錯誤:
cursor = db.query(DATABASE_TABLECa, new String[]{ key_RoWid ,Key_GroupName}, null, null, null, null, null);
public List<ListAdapterdb> Getall() {
List<ListAdapterdb> dataList = new ArrayList<ListAdapterdb>();
db = dbhelper.getReadableDatabase();
Cursor cursor= null;
cursor = db.query(DATABASE_TABLECa, new String[]{ key_RoWid ,Key_GroupName}, null, null, null, null, null);
if (cursor.moveToFirst()) {
do {
ListAdapterdb data = new ListAdapterdb();
//data.setID(Integer.parseInt(cursor.getString(0)));
data.setItem(cursor.getString(1));
// Adding contact to list
dataList.add(data);
} while (cursor.moveToNext());
}
return dataList;
}
處理完數據后,您需要調用cursor.close()
。
try {
ListAdapterdb data = new ListAdapterdb();
while (cursor.moveToNext()) {
// data.setID(Integer.parseInt(cursor.getString(0)));
data.setItem(cursor.getString(1));
// Adding contact to list
dataList.add(data);
}
} finally {
cursor.close()
}
您還可以將此代碼添加到該行: @SuppressLint("Recycle")
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.