0

Room Database Migrate method

    public void migrate(SupportSQLiteDatabase database) {
        database.execSQL("ALTER TABLE menuItems ADD COLUMN cnt INTEGER DEFAULT 0 NOT NULL");
    }

database is throwing an error

java.lang.IllegalStateException: attempt to re-open an already-closed object: SQLiteDatabase:

I have not used database close method anywhere in the method. I am not able to alter database table. How to get rid of above exception.

I tried to open database in migrate method.

MikeT
  • 51,415
  • 16
  • 49
  • 68
raghu
  • 30
  • 5
  • 2
    The object that has been closed can't be reopened is an SQLiteDatabase rather than a SupportSQLiteDatabase. I would suggest that you edit your question to include more of the stack trace and also the code to which it points to. – MikeT Feb 06 '23 at 07:38
  • i think this is help you https://stackoverflow.com/questions/23166323/attempt-to-reopen-an-already-closed-object-sqlitedatabase – Hanif Shaikh Feb 06 '23 at 09:20

1 Answers1

0

we migrated to room latest version and used automigrationspec to solve this issue

raghu
  • 30
  • 5