android - Room Persistence Library: attempt to re-open an already-closed object -
everything working fine when using 1.0.0-alpha5 version of room persistence library. but, after updating 1.0.0-alpha9 version, getting error:
java.lang.illegalstateexception: attempt re-open already-closed object: sqlitedatabase: /data/data/package_name/databases/app_db
how can solve this?
edit:
i using mvp architecture dagger 2. have got databasehelper class initializes roomdatabase:
@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<difficultyentity> getalldifficulties() { return appdatabase.difficultydao().getalldifficulties(); }
my roomdatabase:
@database(version = 22, entities = { difficultyentity.class, // .... }) @singleton public abstract class appdatabase extends roomdatabase { public abstract difficultydao difficultydao(); //.... }
when call getalldifficulties
method, getting error.
here's logcat:
java.lang.illegalstateexception: attempt re-open already-closed object: sqlitedatabase: /data/data/package_name/databases/app_db @ android.database.sqlite.sqliteclosable.acquirereference(sqliteclosable.java:55) @ android.database.sqlite.sqlitedatabase.executesql(sqlitedatabase.java:1783) @ android.database.sqlite.sqlitedatabase.execsql(sqlitedatabase.java:1729) @ android.arch.persistence.db.framework.frameworksqlitedatabase.execsql(frameworksqlitedatabase.java:241) @ android.arch.persistence.room.roomopenhelper.createmastertableifnotexists(roomopenhelper.java:130) @ android.arch.persistence.room.roomopenhelper.checkidentity(roomopenhelper.java:106) @ android.arch.persistence.room.roomopenhelper.onopen(roomopenhelper.java:99) @ android.arch.persistence.db.framework.frameworksqliteopenhelper$1.onopen(frameworksqliteopenhelper.java:64) @ android.database.sqlite.sqliteopenhelper.getdatabaselocked(sqliteopenhelper.java:266) @ android.database.sqlite.sqliteopenhelper.getwritabledatabase(sqliteopenhelper.java:163) @ android.arch.persistence.db.framework.frameworksqliteopenhelper$openhelper.getwritablesupportdatabase(frameworksqliteopenhelper.java:106) @ android.arch.persistence.db.framework.frameworksqliteopenhelper.getwritabledatabase(frameworksqliteopenhelper.java:82) @ android.arch.persistence.room.roomdatabase.query(roomdatabase.java:191) @ uz.iumarov.ieltsspeaking.data.local.database.daos.recordingdao_impl.getallrecordings(recordingdao_impl.java:167) @ uz.iumarov.ieltsspeaking.data.local.database.databasehelper.getallrecording(databasehelper.java:361) @ uz.iumarov.ieltsspeaking.ui.main.recordingsfragment.recordingspresenter$1.call(recordingspresenter.java:77) @ uz.iumarov.ieltsspeaking.ui.main.recordingsfragment.recordingspresenter$1.call(recordingspresenter.java:74) @ rx.internal.operators.onsubscribedefer.call(onsubscribedefer.java:46) @ rx.internal.operators.onsubscribedefer.call(onsubscribedefer.java:35) @ rx.internal.operators.onsubscribelift.call(onsubscribelift.java:48) @ rx.internal.operators.onsubscribelift.call(onsubscribelift.java:30) @ rx.observable.unsafesubscribe(observable.java:10151) @ rx.internal.operators.onsubscribemap.call(onsubscribemap.java:48) @ rx.internal.operators.onsubscribemap.call(onsubscribemap.java:33) @ rx.internal.operators.onsubscribelift.call(onsubscribelift.java:48) @ rx.internal.operators.onsubscribelift.call(onsubscribelift.java:30) @ rx.observable.unsafesubscribe(observable.java:10151) @ rx.internal.operators.operatorsubscribeon$1.call(operatorsubscribeon.java:94) @ rx.internal.schedulers.eventloopsscheduler$eventloopworker$1.call(eventloopsscheduler.java:172) @ rx.internal.schedulers.scheduledaction.run(scheduledaction.java:55) @ java.util.concurrent.executors$runnableadapter.call(executors.java:422) @ java.util.concurrent.futuretask.run(futuretask.java:237) @ java.util.concurrent.scheduledthreadpoolexecutor$scheduledfuturetask.access$201(scheduledthreadpoolexecutor.java:152) @ java.util.concurrent.scheduledthreadpoolexecutor$scheduledfuturetask.run(scheduledthreadpoolexecutor.java:265) @ java.util.concurrent.threadpoolexecutor.runworker(threadpoolexecutor.java:1112) @ java.util.concurrent.threadpoolexecutor$worker.run(threadpoolexecutor.java:587) @ java.lang.thread.run(thread.java:818)
edit 2:
after time, started getting different error:
java.lang.illegalstateexception: room cannot verify data integrity. looks you've changed schema forgot update version number. can fix increasing version number. @ android.arch.persistence.room.roomopenhelper.checkidentity(roomopenhelper.java:118) @ android.arch.persistence.room.roomopenhelper.onopen(roomopenhelper.java:99) @ android.arch.persistence.db.framework.frameworksqliteopenhelper$1.onopen(frameworksqliteopenhelper.java:64) @ android.database.sqlite.sqliteopenhelper.getdatabaselocked(sqliteopenhelper.java:266) @ android.database.sqlite.sqliteopenhelper.getwritabledatabase(sqliteopenhelper.java:163) @ android.arch.persistence.db.framework.frameworksqliteopenhelper$openhelper.getwritablesupportdatabase(frameworksqliteopenhelper.java:106) @ android.arch.persistence.db.framework.frameworksqliteopenhelper.getwritabledatabase(frameworksqliteopenhelper.java:82) @ android.arch.persistence.room.roomdatabase.query(roomdatabase.java:191) @ uz.iumarov.ieltsspeaking.data.local.database.daos.recordingdao_impl.getallrecordings(recordingdao_impl.java:167) @ uz.iumarov.ieltsspeaking.data.local.database.databasehelper.getallrecording(databasehelper.java:361) @ uz.iumarov.ieltsspeaking.ui.main.recordingsfragment.recordingspresenter$1.call(recordingspresenter.java:77) @ uz.iumarov.ieltsspeaking.ui.main.recordingsfragment.recordingspresenter$1.call(recordingspresenter.java:74) @ rx.internal.operators.onsubscribedefer.call(onsubscribedefer.java:46) @ rx.internal.operators.onsubscribedefer.call(onsubscribedefer.java:35) @ rx.internal.operators.onsubscribelift.call(onsubscribelift.java:48) @ rx.internal.operators.onsubscribelift.call(onsubscribelift.java:30) @ rx.observable.unsafesubscribe(observable.java:10151) @ rx.internal.operators.onsubscribemap.call(onsubscribemap.java:48) @ rx.internal.operators.onsubscribemap.call(onsubscribemap.java:33) @ rx.internal.operators.onsubscribelift.call(onsubscribelift.java:48) @ rx.internal.operators.onsubscribelift.call(onsubscribelift.java:30) @ rx.observable.unsafesubscribe(observable.java:10151) @ rx.internal.operators.operatorsubscribeon$1.call(operatorsubscribeon.java:94) @ rx.internal.schedulers.eventloopsscheduler$eventloopworker$1.call(eventloopsscheduler.java:172) @ rx.internal.schedulers.scheduledaction.run(scheduledaction.java:55) @ java.util.concurrent.executors$runnableadapter.call(executors.java:422) @ java.util.concurrent.futuretask.run(futuretask.java:237) @ java.util.concurrent.scheduledthreadpoolexecutor$scheduledfuturetask.access$201(scheduledthreadpoolexecutor.java:152) @ java.util.concurrent.scheduledthreadpoolexecutor$scheduledfuturetask.run(scheduledthreadpoolexecutor.java:265) @ java.util.concurrent.threadpoolexecutor.runworker(threadpoolexecutor.java:1112) @ java.util.concurrent.threadpoolexecutor$worker.run(threadpoolexecutor.java:587) @ java.lang.thread.run(thread.java:818)
and when updated version number, getting migration error:
java.lang.illegalstateexception: migration 22 23 necessary. please provide migration in builder or call fallbacktodestructivemigration in builder in case room re-create of tables. @ android.arch.persistence.room.roomopenhelper.onupgrade(roomopenhelper.java:81) @ android.arch.persistence.db.framework.frameworksqliteopenhelper$1.onupgrade(frameworksqliteopenhelper.java:49) @ android.database.sqlite.sqliteopenhelper.getdatabaselocked(sqliteopenhelper.java:256) @ android.database.sqlite.sqliteopenhelper.getwritabledatabase(sqliteopenhelper.java:163) @ android.arch.persistence.db.framework.frameworksqliteopenhelper$openhelper.getwritablesupportdatabase(frameworksqliteopenhelper.java:106) @ android.arch.persistence.db.framework.frameworksqliteopenhelper.getwritabledatabase(frameworksqliteopenhelper.java:82) @ android.arch.persistence.room.roomdatabase.query(roomdatabase.java:191) @ uz.iumarov.ieltsspeaking.data.local.database.daos.recordingdao_impl.getallrecordings(recordingdao_impl.java:167) @ uz.iumarov.ieltsspeaking.data.local.database.databasehelper.getallrecording(databasehelper.java:361) @ uz.iumarov.ieltsspeaking.ui.main.recordingsfragment.recordingspresenter$1.call(recordingspresenter.java:77) @ uz.iumarov.ieltsspeaking.ui.main.recordingsfragment.recordingspresenter$1.call(recordingspresenter.java:74) @ rx.internal.operators.onsubscribedefer.call(onsubscribedefer.java:46) @ rx.internal.operators.onsubscribedefer.call(onsubscribedefer.java:35) @ rx.internal.operators.onsubscribelift.call(onsubscribelift.java:48) @ rx.internal.operators.onsubscribelift.call(onsubscribelift.java:30) @ rx.observable.unsafesubscribe(observable.java:10151) @ rx.internal.operators.onsubscribemap.call(onsubscribemap.java:48) @ rx.internal.operators.onsubscribemap.call(onsubscribemap.java:33) @ rx.internal.operators.onsubscribelift.call(onsubscribelift.java:48) @ rx.internal.operators.onsubscribelift.call(onsubscribelift.java:30) @ rx.observable.unsafesubscribe(observable.java:10151) @ rx.internal.operators.operatorsubscribeon$1.call(operatorsubscribeon.java:94) @ rx.internal.schedulers.eventloopsscheduler$eventloopworker$1.call(eventloopsscheduler.java:172) @ rx.internal.schedulers.scheduledaction.run(scheduledaction.java:55) @ java.util.concurrent.executors$runnableadapter.call(executors.java:422) @ java.util.concurrent.futuretask.run(futuretask.java:237) @ java.util.concurrent.scheduledthreadpoolexecutor$scheduledfuturetask.access$201(scheduledthreadpoolexecutor.java:152) @ java.util.concurrent.scheduledthreadpoolexecutor$scheduledfuturetask.run(scheduledthreadpoolexecutor.java:265) @ java.util.concurrent.threadpoolexecutor.runworker(threadpoolexecutor.java:1112) @ java.util.concurrent.threadpoolexecutor$worker.run(threadpoolexecutor.java:587) @ java.lang.thread.run(thread.java:818)
please, me!
solved
i deleted app , reinstalled. now, working fine alpha9 verison.
you have provide migration.in live app can't tell every person please delete app , reinstall app.
in room new version 1.0.0-alpha9 room adds support not null constraint.
that going change schema room generates. because changes schema, changes identityhash of db , used room uniquely identify every db version. therefore, need migration
for migration 1.0.0-alpha5 1.0.0-alpha9 please visit below article. article migrate old version 1.0.0-alpha9 version.
wiki
Comments
Post a Comment