尝试/检入功能以检查数据库是否存在未捕获异常

时间:2014-09-05 19:32:50

标签: android sqlite

我使用这个函数来检查数据库是否存在,它应该抛出错误,但它会抛出异常并导致我的应用程序崩溃,为什么会这样?

private boolean checkDataBase() {
        SQLiteDatabase checkDB = null;
        try {
            checkDB = SQLiteDatabase.openDatabase(
                    "/data/data/com.pickante.app/databases/pickante", null,
                    SQLiteDatabase.OPEN_READONLY);
            checkDB.close();
        } catch (SQLiteException e) {
            // database doesn't exist yet.
        }
        return checkDB != null ? true : false;

    }

Log Cat:

09-05 19:27:57.397: E/SQLiteLog(3003): (14) cannot open file at line 30191 of [00bb9c9ce4]
09-05 19:27:57.401: E/SQLiteLog(3003): (14) os_unix.c:30191: (2) open(/data/data/com.pickante.app/databases/pickante) - 
09-05 19:27:57.421: E/SQLiteDatabase(3003): Failed to open database '/data/data/com.pickante.app/databases/pickante'.
09-05 19:27:57.421: E/SQLiteDatabase(3003): android.database.sqlite.SQLiteCantOpenDatabaseException: unknown error (code 14): Could not open database
09-05 19:27:57.421: E/SQLiteDatabase(3003):     at android.database.sqlite.SQLiteConnection.nativeOpen(Native Method)
09-05 19:27:57.421: E/SQLiteDatabase(3003):     at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:209)
09-05 19:27:57.421: E/SQLiteDatabase(3003):     at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:193)
09-05 19:27:57.421: E/SQLiteDatabase(3003):     at android.database.sqlite.SQLiteConnectionPool.openConnectionLocked(SQLiteConnectionPool.java:463)
09-05 19:27:57.421: E/SQLiteDatabase(3003):     at android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:185)
09-05 19:27:57.421: E/SQLiteDatabase(3003):     at android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:177)
09-05 19:27:57.421: E/SQLiteDatabase(3003):     at android.database.sqlite.SQLiteDatabase.openInner(SQLiteDatabase.java:804)
09-05 19:27:57.421: E/SQLiteDatabase(3003):     at android.database.sqlite.SQLiteDatabase.open(SQLiteDatabase.java:789)
09-05 19:27:57.421: E/SQLiteDatabase(3003):     at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:694)
09-05 19:27:57.421: E/SQLiteDatabase(3003):     at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:669)
09-05 19:27:57.421: E/SQLiteDatabase(3003):     at com.pickante.app.SplashScreen.checkDataBase(SplashScreen.java:128)
09-05 19:27:57.421: E/SQLiteDatabase(3003):     at com.pickante.app.SplashScreen.onCreate(SplashScreen.java:52)
09-05 19:27:57.421: E/SQLiteDatabase(3003):     at android.app.Activity.performCreate(Activity.java:5133)
09-05 19:27:57.421: E/SQLiteDatabase(3003):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
09-05 19:27:57.421: E/SQLiteDatabase(3003):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2175)
09-05 19:27:57.421: E/SQLiteDatabase(3003):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
09-05 19:27:57.421: E/SQLiteDatabase(3003):     at android.app.ActivityThread.access$600(ActivityThread.java:141)
09-05 19:27:57.421: E/SQLiteDatabase(3003):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
09-05 19:27:57.421: E/SQLiteDatabase(3003):     at android.os.Handler.dispatchMessage(Handler.java:99)
09-05 19:27:57.421: E/SQLiteDatabase(3003):     at android.os.Looper.loop(Looper.java:137)
09-05 19:27:57.421: E/SQLiteDatabase(3003):     at android.app.ActivityThread.main(ActivityThread.java:5103)
09-05 19:27:57.421: E/SQLiteDatabase(3003):     at java.lang.reflect.Method.invokeNative(Native Method)
09-05 19:27:57.421: E/SQLiteDatabase(3003):     at java.lang.reflect.Method.invoke(Method.java:525)
09-05 19:27:57.421: E/SQLiteDatabase(3003):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
09-05 19:27:57.421: E/SQLiteDatabase(3003):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
09-05 19:27:57.421: E/SQLiteDatabase(3003):     at dalvik.system.NativeStart.main(Native Method)
09-05 19:27:57.477: W/EGL_genymotion(3003): eglSurfaceAttrib not implemented

0 个答案:

没有答案