Android 项目作为库 - sqllite 数据库问题

发布于 2024-12-10 10:16:54 字数 543 浏览 0 评论 0原文

我有一个小测验项目,它作为库添加到主项目中,似乎一切正常,除了连接到 sqlite 数据库时,我收到以下错误:

10-16 22:10:47.942: ERROR/Cursor(5868): Finalizing a Cursor that has not been deactivated or closed. database = /data/data/org.ttrssreader/databases/ttrss.db, table = null, query = SELECT id,title,unread FROM categories WHERE id>0 ORDER BY UPPER(title) ASC
10-16 22:10:47.942: ERROR/Cursor(5868): android.database.sqlite.DatabaseObjectNotClosedException: Application did not close the cursor or database object that was opened here

非常感谢任何帮助...

I have a little quiz project that am adding as a library to a main project, everything seems to work except when it comes to connecting to the sqlite database, I get the following error:

10-16 22:10:47.942: ERROR/Cursor(5868): Finalizing a Cursor that has not been deactivated or closed. database = /data/data/org.ttrssreader/databases/ttrss.db, table = null, query = SELECT id,title,unread FROM categories WHERE id>0 ORDER BY UPPER(title) ASC
10-16 22:10:47.942: ERROR/Cursor(5868): android.database.sqlite.DatabaseObjectNotClosedException: Application did not close the cursor or database object that was opened here

anyhelp is greatly appreciated...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

物价感观 2024-12-17 10:16:54

听起来您没有清理游标或打开数据库。每次执行返回游标对象的数据库操作时,在读取完数据后都必须对游标调用 close()。另外,当您完成数据库本身的操作后,您应该调用数据库的 close 方法。

如果您为同一数据库创建 SQLiteOpenHelper 的多个实例,也可能会发生这种情况。您应该只实例化一次 SQLiteOpenHelper 子类,并为所有进一步的数据库操作保留对它的引用。

It sounds like you aren't cleaning up your cursors or open database. Every time that you perform a database operation that returns a cursor object, you must call close() on the cursor when you are done reading data from it. Also, when you are done with the database itself, you should call close on the database.

This can also happen if you create multiple instances of SQLiteOpenHelper for the same database. You should just instantiate a SQLiteOpenHelper subclass once and keep a reference to it for all further DB operations.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文