开发者

android database already close onResume

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();


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜