android 数据库已经关闭 onResume
我的应用程序有一个问题,如果我返回到某个活动,我会收到数据库已关闭的错误:
ERROR/AndroidRuntime(3566): Caused by: java.lang.IllegalStateException: database /data/data/com.kempville.app/databases/MyDB already closed
我实例化、打开、实例化游标、执行查询、关闭游标并关闭数据库,所有这些都在期间调用的方法中进行onResume()。我不知道当此活动回到前台时调用 onResume 时假定打开的内容。
private void getMydata() {
MyDb db;
db = new MyDB(this);
db.open();
Cursor c = db.getInfo(code);
startManagingCursor(c);
if (c.moveToFirst()) {
name = c.getString(c.getColumnIndex("name"));
}
c = fdb.getType(myArray.getString("type"));
startManagingCursor(c);
if (c.moveToFirst()) {
type = c.getString(c.getColumnIndex("type"));
}
c.close();
db.close();
my application has an issue where if I go back to an activity I get an error that the database has been closed:
ERROR/AndroidRuntime(3566): Caused by: java.lang.IllegalStateException: database /data/data/com.kempville.app/databases/MyDB already closed
I instantiate, open, instatiate a cursor, do the query, close the cursor and close the database all within a method called during onResume(). I don't know what is assumed to be open whenever onResume gets called when this activity comes back to the front.
private void getMydata() {
MyDb db;
db = new MyDB(this);
db.open();
Cursor c = db.getInfo(code);
startManagingCursor(c);
if (c.moveToFirst()) {
name = c.getString(c.getColumnIndex("name"));
}
c = fdb.getType(myArray.getString("type"));
startManagingCursor(c);
if (c.moveToFirst()) {
type = c.getString(c.getColumnIndex("type"));
}
c.close();
db.close();
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
似乎 startManagingCursor 会尝试关闭它,尽管您自己已经关闭了它。要么删除 startManagingCursor (它已被弃用),要么最好调用 stopManagingCursor
Seems that startManagingCursor will try to close it, though you've closed it yourself. Either drop the startManagingCursor (it's getting deprecated) or better call stopManagingCursor