[英]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.