我收到房间数据库无法执行查询的崩溃报告,因为数据库已经关闭。我尝试重现这个错误,但我似乎无法得到它。
java.lang.IllegalStateException: attempt to re-open an already-closed object: SQLiteDatabase: /data/user/0/...
at android.database.sqlite.SQLiteClosable.acquireReference(SQLiteClosable.java:55)
at android.database.sqlite.SQLiteDatabase.executeSql(SQLiteDatabase.java:1950)
at android.database.sqlite.SQLiteDatabase.execSQL(SQLiteDatabase.java:1890)
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:282)
at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:175)
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.inTransaction(RoomDatabase.java:305)
at android.arch.persistence.room.InvalidationTracker$1.run(InvalidationTracker.java:281)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
at java.lang.Thread.run(Thread.java:776)
数据库初始化代码:
public static Database getDataBase(HomieApplication application) {
return Room.databaseBuilder(application, Database.class, "Mydata").allowMainThreadQueries().fallbackToDestructiveMigration().build();
}
道:
@Dao
public interface SearchDao {
@Insert(onConflict = OnConflictStrategy.REPLACE)
void saveQueries(List<SearchQuery> queries);
@Query("DELETE FROM SearchQuery")
void deleteAllSearchQueries();
@Query("SELECT * FROM SearchQuery")
LiveData<List<SearchQuery>> getSearchQueries();
@Insert(onConflict = OnConflictStrategy.REPLACE)
void saveLastBounds(Bounds bounds);
@Query("SELECT * FROM Bounds where id LIKE :id")
Bounds getLastBounds(int id);
}