为什么应用程序更新到新版本后不存在 SQLite 数据库?即使数据库之前确实存在,它怎么可能不再存在。
(使用安卓 2.3.3)
错误日志 为什么 SQLiteOpenHelper.getWritableDatabase() 会导致此异常?当然,意识到“哦,数据库不存在,让我们创建它!
请注意,new SQLiteOpenHelper(context)
据我所知,工作正常。但是,我不知道是否onCreate()
被onUpgrade()
触发。
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 with 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): at myapp.com.MyActivity.onCreate(MyActivity.java:131)
06-04 18:21:01.745 E/AndroidRuntime( 1280): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
06-04 18:21:01.745 E/AndroidRuntime( 1280): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
06-04 18:21:01.745 E/AndroidRuntime( 1280): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
06-04 18:21:01.745 E/AndroidRuntime( 1280): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
06-04 18:21:01.745 E/AndroidRuntime( 1280): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
06-04 18:21:01.745 E/AndroidRuntime( 1280): at android.os.Handler.dispatchMessage(Handler.java:99)
06-04 18:21:01.745 E/AndroidRuntime( 1280): at android.os.Looper.loop(Looper.java:130)
06-04 18:21:01.745 E/AndroidRuntime( 1280): at android.app.ActivityThread.main(ActivityThread.java:3683)
06-04 18:21:01.745 E/AndroidRuntime( 1280): at java.lang.reflect.Method.invokeNative(Native Method)
06-04 18:21:01.745 E/AndroidRuntime( 1280): at java.lang.reflect.Method.invoke(Method.java:507)
06-04 18:21:01.745 E/AndroidRuntime( 1280): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
06-04 18:21:01.745 E/AndroidRuntime( 1280): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
06-04 18:21:01.745 E/AndroidRuntime( 1280): at dalvik.system.NativeStart.main(Native Method)
06-04 18:21:01.745 E/AndroidRuntime( 1280): Caused by: android.database.sqlite.SQLiteException: unable to open database file
06-04 18:21:01.745 E/AndroidRuntime( 1280): at android.database.sqlite.SQLiteDatabase.dbopen(Native Method)
06-04 18:21:01.745 E/AndroidRuntime( 1280): at android.database.sqlite.SQLiteDatabase.<init>(SQLiteDatabase.java:1849)
06-04 18:21:01.745 E/AndroidRuntime( 1280): at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:820)
06-04 18:21:01.745 E/AndroidRuntime( 1280): at android.database.sqlite.SQLiteDatabase.openOrCreateDatabase(SQLiteDatabase.java:854)
06-04 18:21:01.745 E/AndroidRuntime( 1280): at android.database.sqlite.SQLiteDatabase.openOrCreateDatabase(SQLiteDatabase.java:847)
06-04 18:21:01.745 E/AndroidRuntime( 1280): at android.app.ContextImpl.openOrCreateDatabase(ContextImpl.java:547)
06-04 18:21:01.745 E/AndroidRuntime( 1280): at android.content.ContextWrapper.openOrCreateDatabase(ContextWrapper.java:203)
06-04 18:21:01.745 E/AndroidRuntime( 1280): at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:118)
06-04 18:21:01.745 E/AndroidRuntime( 1280): at myapp.com.storage.SQLiteStorage.<init>(SQLiteStorage.java:61)
06-04 18:21:01.745 E/AndroidRuntime( 1280): at 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
在我捕获异常“SQLiteException:无法打开数据库文件”之后,应用程序是否应该简单地尝试实例化另一个 SQLiteOpenHelper ?