Cursor cursor=null;
Cursor cursor2=null;
db = helper.getReadableDatabase();
try{
cursor=rawQuery("...",null);
while (cursor.moveToNext())
{
// ...
cursor2=db.rawQuery("select file_path from memos where time > "+date+" and time < "+lg+" order by time desc",null);
if(cursor2.moveToNext()){
//...
}
cursor2.close(); // 因是在循环内,要在此处加上关闭,而不仅只在finally中关闭
// ...
}
}
}finally{
if(cursor!=null){
cursor.close();
}
if(cursor2!=null){
cursor2.close();
}
db.close(); // 此处可以根据情况关闭与否
}
android.database.sqlite.DatabaseObjectNotClosedException: Application did not close the cursor or da
最新推荐文章于 2019-06-18 15:26:46 发布
本文详细介绍了使用 SQLite 进行数据库查询的过程,包括如何通过 rawQuery 方法获取数据,并在循环中进行多次子查询。此外,还强调了正确管理 Cursor 对象及数据库连接的重要性,以避免内存泄漏。
AI 时代程序员必备技能
Codex、Claude Code、Cursor、Hermes Agent、OpenClaw等工程化实战专栏 ,讲透 AI 如何接管脏活累活
AI 时代程序员必备技能
Codex、Claude Code、Cursor、Hermes Agent、OpenClaw等工程化实战专栏 ,讲透 AI 如何接管脏活累活


1万+

被折叠的 条评论
为什么被折叠?



