关于SQLite,java.lang.IllegalStateException: attempt to re-open an already-closed object

前端之家收集整理的这篇文章主要介绍了关于SQLite,java.lang.IllegalStateException: attempt to re-open an already-closed object前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
java.lang.IllegalStateException: attempt to re-open an already-closed object: sqliteQuery: select groupname from newGroupInfo order by _id desc limit ? offset ? @H_502_2@ at android.database.sqlite.sqliteClosable.acquireReference(sqliteClosable.java:55) @H_502_2@ at android.database.sqlite.sqliteQuery.fillWindow(sqliteQuery.java:58) @H_502_2@ at android.database.sqlite.sqliteCursor.fillWindow(sqliteCursor.java:152)at android.database.sqlite.sqliteCursor.onMove(sqliteCursor.java:124) @H_502_2@ at android.database.AbstractCursor.moveToPosition(AbstractCursor.java:214) @H_502_2@ at android.database.AbstractCursor.moveToNext(AbstractCursor.java:245) @H_502_2@ at com.example.invite.dao.AddGroupDao.findPart(AddGroupDao.java:97) @H_502_2@

at com.example.invite.MainActivity$2.run(MainActivity.java:96)




原文:while (cursor.moveToNext()) {
MyGroupInfo myGroupInfo = new MyGroupInfo();
String groupname = cursor.getString(0);
// myGroupInfo.setGroupName(cursor.getString(0));
myGroupInfo.setGroupName(groupname);
myGroupInfos.add(myGroupInfo);

cursor.close();
db.close();

}

看了一下,原来我的sqliteDatabase对象关闭放在了while的里面。以至于报错了。所以解决方法就是把他们放到外面去,记得要关闭,但位置要看清。这篇小博文就作为自己开始真正工作的起点,也方便自己回忆学习。

猜你在找的Sqlite相关文章