尝试重新打开已经关闭的对象sqlite

时间:2018-05-29 12:22:33

标签: android android-sqlite android-room

我正在使用Android Room 1.0.0 for DB。在运行应用程序时,我得到以下错误。

  java.lang.IllegalStateException: attempt to re-open an already-closed object: SQLiteDatabase: /data/user/0/com.abc.mypkg/databases/myapp
                                                                   at android.database.sqlite.SQLiteClosable.acquireReference(SQLiteClosable.java:55)
                                                                   at android.database.sqlite.SQLiteDatabase.executeSql(SQLiteDatabase.java:2086)
                                                                   at android.database.sqlite.SQLiteDatabase.execSQL(SQLiteDatabase.java:2032)
                                                                   at android.arch.persistence.db.framework.FrameworkSQLiteDatabase.execSQL(FrameworkSQLiteDatabase.java:240)
                                                                   at android.arch.persistence.room.RoomOpenHelper.createMasterTableIfNotExists(RoomOpenHelper.java:131)
                                                                   at android.arch.persistence.room.RoomOpenHelper.checkIdentity(RoomOpenHelper.java:107)
                                                                   at android.arch.persistence.room.RoomOpenHelper.onOpen(RoomOpenHelper.java:100)
                                                                   at android.arch.persistence.db.framework.FrameworkSQLiteOpenHelper$OpenHelper.onOpen(FrameworkSQLiteOpenHelper.java:133)
                                                                   at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:310)
                                                                   at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:194)
                                                                   at android.arch.persistence.db.framework.FrameworkSQLiteOpenHelper$OpenHelper.getWritableSupportDatabase(FrameworkSQLiteOpenHelper.java:93)
                                                                   at android.arch.persistence.db.framework.FrameworkSQLiteOpenHelper.getWritableDatabase(FrameworkSQLiteOpenHelper.java:54)
                                                                   at android.arch.persistence.room.RoomDatabase.query(RoomDatabase.java:193)
                                                                   at com.jpmc.appstore.db.AppItemDao_Impl$11.compute(AppItemDao_Impl.java:415)
                                                                   at com.jpmc.appstore.db.AppItemDao_Impl$11.compute(AppItemDao_Impl.java:401)
                                                                   at android.arch.lifecycle.ComputableLiveData$2.run(ComputableLiveData.java:87)
                                                                   at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
                                                                   at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
                                                                   at java.lang.Thread.run(Thread.java:764)

它并不总是,它来自10个中的一次或两次,但是当它到来时,我需要卸载应用程序并安装。它甚至还应用于全新安装的应用程序。 我用了#fallbackToDestructiveMigration()'但也没有帮助。

想了解它的根本原因。在生产中对我来说可能是危险的。

1 个答案:

答案 0 :(得分:0)

我使用的是Room 1.1.1-rc1,现在工作正常。