android - after update: "SQLiteException: unable to open database file" -


why wouldn't there exist sqlite database after app updated new version ? how possible database no longer present though did exist earlier.

(using android 2.3.3)

error log why sqliteopenhelper.getwritabledatabase() cause exception? surely clever enough realize "oooh db doesn't exist, let's create it!

note new sqliteopenhelper(context) worked ok far can tell. however, not know whether oncreate() or onupgrade() triggered.

06-04 18:21:01.706 d/androidruntime( 1280): shutting down vm 06-04 18:21:01.706 w/dalvikvm( 1280): threadid=1: thread exiting uncaught exception (group=0x40015560) 06-04 18:21:01.745 e/androidruntime( 1280): fatal exception: main 06-04 18:21:01.745 e/androidruntime( 1280): java.lang.exceptionininitializererror 06-04 18:21:01.745 e/androidruntime( 1280):     @ myapp.com.myactivity.oncreate(myactivity.java:131) 06-04 18:21:01.745 e/androidruntime( 1280):     @ android.app.instrumentation.callactivityoncreate(instrumentation.java:1047) 06-04 18:21:01.745 e/androidruntime( 1280):     @ android.app.activitythread.performlaunchactivity(activitythread.java:1611) 06-04 18:21:01.745 e/androidruntime( 1280):     @ android.app.activitythread.handlelaunchactivity(activitythread.java:1663) 06-04 18:21:01.745 e/androidruntime( 1280):     @ android.app.activitythread.access$1500(activitythread.java:117) 06-04 18:21:01.745 e/androidruntime( 1280):     @ android.app.activitythread$h.handlemessage(activitythread.java:931) 06-04 18:21:01.745 e/androidruntime( 1280):     @ android.os.handler.dispatchmessage(handler.java:99) 06-04 18:21:01.745 e/androidruntime( 1280):     @ android.os.looper.loop(looper.java:130) 06-04 18:21:01.745 e/androidruntime( 1280):     @ android.app.activitythread.main(activitythread.java:3683) 06-04 18:21:01.745 e/androidruntime( 1280):     @ java.lang.reflect.method.invokenative(native method) 06-04 18:21:01.745 e/androidruntime( 1280):     @ java.lang.reflect.method.invoke(method.java:507) 06-04 18:21:01.745 e/androidruntime( 1280):     @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:839) 06-04 18:21:01.745 e/androidruntime( 1280):     @ com.android.internal.os.zygoteinit.main(zygoteinit.java:597) 06-04 18:21:01.745 e/androidruntime( 1280):     @ dalvik.system.nativestart.main(native method) 06-04 18:21:01.745 e/androidruntime( 1280): caused by: android.database.sqlite.sqliteexception: unable open database file 06-04 18:21:01.745 e/androidruntime( 1280):     @ android.database.sqlite.sqlitedatabase.dbopen(native method) 06-04 18:21:01.745 e/androidruntime( 1280):     @ android.database.sqlite.sqlitedatabase.<init>(sqlitedatabase.java:1849) 06-04 18:21:01.745 e/androidruntime( 1280):     @ android.database.sqlite.sqlitedatabase.opendatabase(sqlitedatabase.java:820) 06-04 18:21:01.745 e/androidruntime( 1280):     @ android.database.sqlite.sqlitedatabase.openorcreatedatabase(sqlitedatabase.java:854) 06-04 18:21:01.745 e/androidruntime( 1280):     @ android.database.sqlite.sqlitedatabase.openorcreatedatabase(sqlitedatabase.java:847) 06-04 18:21:01.745 e/androidruntime( 1280):     @ android.app.contextimpl.openorcreatedatabase(contextimpl.java:547) 06-04 18:21:01.745 e/androidruntime( 1280):     @ android.content.contextwrapper.openorcreatedatabase(contextwrapper.java:203) 06-04 18:21:01.745 e/androidruntime( 1280):     @ android.database.sqlite.sqliteopenhelper.getwritabledatabase(sqliteopenhelper.java:118) 06-04 18:21:01.745 e/androidruntime( 1280):     @ myapp.com.storage.sqlitestorage.<init>(sqlitestorage.java:61) 06-04 18:21:01.745 e/androidruntime( 1280):     @ myapp.com.storage.sqlitestorage.<clinit>(sqlitestorage.java:58) 06-04 18:21:01.745 e/androidruntime( 1280):     ... 14 more 06-04 18:21:01.776 w/activitymanager( 1002):   force finishing activity myapp.com/.myactivity 

after trap exception "sqliteexception: unable open database file", should app try instantiate sqliteopenhelper ?

i've gotten working reliably (test case force close app, delete .db file created, restart app - requires rooted phone test).

solution:

the sqliteopenhelper object (nested class within sqlitestorage singleton class) needed instantiated application.oncreate() tables ready time service , launcher activity called oncreate()'s

explanation:

what happened launcher activity started service through intent (which used sqlite db storage) , launcher activity initiated sqliteopenhelper.oncreate(). however, because there's lot of tables needed created there existed race condition , database wasn't ready time service wanted it.


Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -