title: Room Persistence Library: attempt to re-open an already-closed object
body: <p>Everything was working fine when I was using 1.0.0-alpha5 version of Room Persistence Library. But, after updating to 1.0.0-alpha9 version, I am getting this error: </p>
  
  <blockquote>
    <p>java.lang.IllegalStateException: attempt to re-open an already-closed
    object: SQLiteDatabase: /data/data/package_name/databases/app_db</p>
  </blockquote>
  
  <p>How can I solve this?</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>I am using MVP architecture with dagger 2. I have got DatabaseHelper class which initializes RoomDatabase:</p>
  
  <pre><code>@Singleton
  public class DatabaseHelper {
  
  private final AppDatabase appDatabase;
  
  @Inject
  public DatabaseHelper(@ApplicationContext Context context) {
      appDatabase = Room.databaseBuilder(context, AppDatabase.class, "app_db").build();        
  }
  
  public List&lt;DifficultyEntity&gt; getAllDifficulties() {
          return appDatabase.difficultyDao().getAllDifficulties();
  }
  </code></pre>
  
  <p>My RoomDatabase:</p>
  
  <pre><code>@Database(version = 22, entities = {
          DifficultyEntity.class, // ....
  })
  @Singleton
  public abstract class AppDatabase extends RoomDatabase {
  
      public abstract DifficultyDao difficultyDao();
      //....
  }
  </code></pre>
  
  <p>When I call <code>getAllDifficulties</code> method, I am getting that error.</p>
  
  <p>Here's logcat:</p>
  
  <pre><code>java.lang.IllegalStateException: attempt to re-open an already-closed object: SQLiteDatabase: /data/data/package_name/databases/app_db
         at android.database.sqlite.SQLiteClosable.acquireReference(SQLiteClosable.java:55)
         at android.database.sqlite.SQLiteDatabase.executeSql(SQLiteDatabase.java:1783)
         at android.database.sqlite.SQLiteDatabase.execSQL(SQLiteDatabase.java:1729)
         at android.arch.persistence.db.framework.FrameworkSQLiteDatabase.execSQL(FrameworkSQLiteDatabase.java:241)
         at android.arch.persistence.room.RoomOpenHelper.createMasterTableIfNotExists(RoomOpenHelper.java:130)
         at android.arch.persistence.room.RoomOpenHelper.checkIdentity(RoomOpenHelper.java:106)
         at android.arch.persistence.room.RoomOpenHelper.onOpen(RoomOpenHelper.java:99)
         at android.arch.persistence.db.framework.FrameworkSQLiteOpenHelper$1.onOpen(FrameworkSQLiteOpenHelper.java:64)
         at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:266)
         at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:163)
         at android.arch.persistence.db.framework.FrameworkSQLiteOpenHelper$OpenHelper.getWritableSupportDatabase(FrameworkSQLiteOpenHelper.java:106)
         at android.arch.persistence.db.framework.FrameworkSQLiteOpenHelper.getWritableDatabase(FrameworkSQLiteOpenHelper.java:82)
         at android.arch.persistence.room.RoomDatabase.query(RoomDatabase.java:191)
         at uz.iumarov.ieltsspeaking.data.local.database.daos.RecordingDao_Impl.getAllRecordings(RecordingDao_Impl.java:167)
         at uz.iumarov.ieltsspeaking.data.local.database.DatabaseHelper.getAllRecording(DatabaseHelper.java:361)
         at uz.iumarov.ieltsspeaking.ui.main.recordingsFragment.RecordingsPresenter$1.call(RecordingsPresenter.java:77)
         at uz.iumarov.ieltsspeaking.ui.main.recordingsFragment.RecordingsPresenter$1.call(RecordingsPresenter.java:74)
         at rx.internal.operators.OnSubscribeDefer.call(OnSubscribeDefer.java:46)
         at rx.internal.operators.OnSubscribeDefer.call(OnSubscribeDefer.java:35)
         at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:48)
         at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:30)
         at rx.Observable.unsafeSubscribe(Observable.java:10151)
         at rx.internal.operators.OnSubscribeMap.call(OnSubscribeMap.java:48)
         at rx.internal.operators.OnSubscribeMap.call(OnSubscribeMap.java:33)
         at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:48)
         at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:30)
         at rx.Observable.unsafeSubscribe(Observable.java:10151)
         at rx.internal.operators.OperatorSubscribeOn$1.call(OperatorSubscribeOn.java:94)
         at rx.internal.schedulers.EventLoopsScheduler$EventLoopWorker$1.call(EventLoopsScheduler.java:172)
         at rx.internal.schedulers.ScheduledAction.run(ScheduledAction.java:55)
         at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:422)
         at java.util.concurrent.FutureTask.run(FutureTask.java:237)
         at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:152)
         at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:265)
         at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
         at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
         at java.lang.Thread.run(Thread.java:818)
  </code></pre>
  
  <p><strong>EDIT 2:</strong></p>
  
  <p>After some time, I started getting different error:</p>
  
  <pre><code>java.lang.IllegalStateException: Room cannot verify the data integrity. Looks like you've changed schema but forgot to update the version number. You can simply fix this by increasing the version number.
         at android.arch.persistence.room.RoomOpenHelper.checkIdentity(RoomOpenHelper.java:118)
         at android.arch.persistence.room.RoomOpenHelper.onOpen(RoomOpenHelper.java:99)
         at android.arch.persistence.db.framework.FrameworkSQLiteOpenHelper$1.onOpen(FrameworkSQLiteOpenHelper.java:64)
         at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:266)
         at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:163)
         at android.arch.persistence.db.framework.FrameworkSQLiteOpenHelper$OpenHelper.getWritableSupportDatabase(FrameworkSQLiteOpenHelper.java:106)
         at android.arch.persistence.db.framework.FrameworkSQLiteOpenHelper.getWritableDatabase(FrameworkSQLiteOpenHelper.java:82)
         at android.arch.persistence.room.RoomDatabase.query(RoomDatabase.java:191)
         at uz.iumarov.ieltsspeaking.data.local.database.daos.RecordingDao_Impl.getAllRecordings(RecordingDao_Impl.java:167)
         at uz.iumarov.ieltsspeaking.data.local.database.DatabaseHelper.getAllRecording(DatabaseHelper.java:361)
         at uz.iumarov.ieltsspeaking.ui.main.recordingsFragment.RecordingsPresenter$1.call(RecordingsPresenter.java:77)
         at uz.iumarov.ieltsspeaking.ui.main.recordingsFragment.RecordingsPresenter$1.call(RecordingsPresenter.java:74)
         at rx.internal.operators.OnSubscribeDefer.call(OnSubscribeDefer.java:46)
         at rx.internal.operators.OnSubscribeDefer.call(OnSubscribeDefer.java:35)
         at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:48)
         at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:30)
         at rx.Observable.unsafeSubscribe(Observable.java:10151)
         at rx.internal.operators.OnSubscribeMap.call(OnSubscribeMap.java:48)
         at rx.internal.operators.OnSubscribeMap.call(OnSubscribeMap.java:33)
         at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:48)
         at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:30)
         at rx.Observable.unsafeSubscribe(Observable.java:10151)
         at rx.internal.operators.OperatorSubscribeOn$1.call(OperatorSubscribeOn.java:94)
         at rx.internal.schedulers.EventLoopsScheduler$EventLoopWorker$1.call(EventLoopsScheduler.java:172)
         at rx.internal.schedulers.ScheduledAction.run(ScheduledAction.java:55)
         at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:422)
         at java.util.concurrent.FutureTask.run(FutureTask.java:237)
         at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:152)
         at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:265)
         at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
         at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
         at java.lang.Thread.run(Thread.java:818)
  </code></pre>
  
  <p>And when I updated the version number, I am getting Migration error:</p>
  
  <pre><code>java.lang.IllegalStateException: A migration from 22 to 23 is necessary. Please provide a Migration in the builder or call fallbackToDestructiveMigration in the builder in which case Room will re-create all of the tables.
         at android.arch.persistence.room.RoomOpenHelper.onUpgrade(RoomOpenHelper.java:81)
         at android.arch.persistence.db.framework.FrameworkSQLiteOpenHelper$1.onUpgrade(FrameworkSQLiteOpenHelper.java:49)
         at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:256)
         at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:163)
         at android.arch.persistence.db.framework.FrameworkSQLiteOpenHelper$OpenHelper.getWritableSupportDatabase(FrameworkSQLiteOpenHelper.java:106)
         at android.arch.persistence.db.framework.FrameworkSQLiteOpenHelper.getWritableDatabase(FrameworkSQLiteOpenHelper.java:82)
         at android.arch.persistence.room.RoomDatabase.query(RoomDatabase.java:191)
         at uz.iumarov.ieltsspeaking.data.local.database.daos.RecordingDao_Impl.getAllRecordings(RecordingDao_Impl.java:167)
         at uz.iumarov.ieltsspeaking.data.local.database.DatabaseHelper.getAllRecording(DatabaseHelper.java:361)
         at uz.iumarov.ieltsspeaking.ui.main.recordingsFragment.RecordingsPresenter$1.call(RecordingsPresenter.java:77)
         at uz.iumarov.ieltsspeaking.ui.main.recordingsFragment.RecordingsPresenter$1.call(RecordingsPresenter.java:74)
         at rx.internal.operators.OnSubscribeDefer.call(OnSubscribeDefer.java:46)
         at rx.internal.operators.OnSubscribeDefer.call(OnSubscribeDefer.java:35)
         at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:48)
         at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:30)
         at rx.Observable.unsafeSubscribe(Observable.java:10151)
         at rx.internal.operators.OnSubscribeMap.call(OnSubscribeMap.java:48)
         at rx.internal.operators.OnSubscribeMap.call(OnSubscribeMap.java:33)
         at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:48)
         at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:30)
         at rx.Observable.unsafeSubscribe(Observable.java:10151)
         at rx.internal.operators.OperatorSubscribeOn$1.call(OperatorSubscribeOn.java:94)
         at rx.internal.schedulers.EventLoopsScheduler$EventLoopWorker$1.call(EventLoopsScheduler.java:172)
         at rx.internal.schedulers.ScheduledAction.run(ScheduledAction.java:55)
         at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:422)
         at java.util.concurrent.FutureTask.run(FutureTask.java:237)
         at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:152)
         at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:265)
         at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
         at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
         at java.lang.Thread.run(Thread.java:818)
  </code></pre>
  
  <p>Please, somebody help me!</p>
  
  <p><strong>SOLVED</strong></p>
  
  <p>I deleted my app and reinstalled. Now, everything is working fine with alpha9 verison.</p>