0
爲什麼我沒有得到SQLite失敗的錯誤代碼?我想創建一個數據庫,並得到以下堆棧跟蹤(當然,跟蹤的頂部):爲什麼沒有sqlite錯誤代碼
E/SqliteDatabaseCpp(11974): sqlite3_open_v2
("/mnt/sdcard/myapp/mydatabase.db", &handle, 6, NULL) failed
E/SQLiteDatabase(11974): Failed to open the database. closing it.
E/SQLiteDatabase(11974): android.database.sqlite.SQLiteCantOpenDatabaseException: unable to open database file
E/SQLiteDatabase(11974): at android.database.sqlite.SQLiteDatabase.dbopen(Native Method)
我的代碼工作在模擬器中,工作在一臺Nexus 7,但沒有其他設備上
public SQLiteDatabase openOrCreateDatabase (String name, int mode,
SQLiteDatabase.CursorFactory factory,
DatabaseErrorHandler errorHandler)
{
File f = getDatabasePath (name);
System.out.println ("opening db: " + f.getPath());
return super.openOrCreateDatabase (f.getPath(), mode, factory, errorHandler);
}
下面是第二次嘗試一個完整的日誌。這與第一個有點不同,但仍然沒有錯誤代碼。
W/dalvikvm(3314): threadid=1: thread exiting with uncaught exception (group=0x40a801f8)
E/AndroidRuntime(3314): FATAL EXCEPTION: main
E/AndroidRuntime(3314): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.myapp.myapp/com.myapp.myapp.main.MainActivity}: android.database.sqlite.SQLiteCantOpenDatabaseException: unable to open database file
E/AndroidRuntime(3314): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956)
E/AndroidRuntime(3314): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
E/AndroidRuntime(3314): at android.app.ActivityThread.access$600(ActivityThread.java:123)
E/AndroidRuntime(3314): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
E/AndroidRuntime(3314): at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime(3314): at android.os.Looper.loop(Looper.java:137)
E/AndroidRuntime(3314): at android.app.ActivityThread.main(ActivityThread.java:4424)
E/AndroidRuntime(3314): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime(3314): at java.lang.reflect.Method.invoke(Method.java:511)
E/AndroidRuntime(3314): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:812)
E/AndroidRuntime(3314): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:579)
E/AndroidRuntime(3314): at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime(3314): Caused by: android.database.sqlite.SQLiteCantOpenDatabaseException: unable to open database file
E/AndroidRuntime(3314): at android.database.sqlite.SQLiteDatabase.dbopen(Native Method)
E/AndroidRuntime(3314): at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:1013)
E/AndroidRuntime(3314): at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:986)
E/AndroidRuntime(3314): at android.database.sqlite.SQLiteDatabase.openOrCreateDatabase(SQLiteDatabase.java:1051)
E/AndroidRuntime(3314): at android.app.ContextImpl.openOrCreateDatabase(ContextImpl.java:782)
E/AndroidRuntime(3314): at android.content.ContextWrapper.openOrCreateDatabase(ContextWrapper.java:221)
E/AndroidRuntime(3314): at android.content.ContextWrapper.openOrCreateDatabase(ContextWrapper.java:221)
E/AndroidRuntime(3314): at com.myapp.myapp.dbaccess.DatabaseContext.openOrCreateDatabase(DbHelper.java:63)
E/AndroidRuntime(3314): at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:157)
E/AndroidRuntime(3314): at com.myapp.myapp.dbaccess.DbHelper.getDb(DbHelper.java:184)
E/AndroidRuntime(3314): at com.myapp.myapp.dbaccess.DbHelper.getZRoot(DbHelper.java:650)
E/AndroidRuntime(3314): at com.myapp.myapp.dbaccess.ZNodeCache.getRequiredNodes(ZNodeCache.java:37)
E/AndroidRuntime(3314): at com.myapp.myapp.dbaccess.ZNodeCache.<init>(ZNodeCache.java:22)
E/AndroidRuntime(3314): at com.myapp.myapp.main.MainActivity.onCreate(MainActivity.java:81)
E/AndroidRuntime(3314): at android.app.Activity.performCreate(Activity.java:4465)
E/AndroidRuntime(3314): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
E/AndroidRuntime(3314): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
E/AndroidRuntime(3314): ... 11 more
「爲什麼我沒有收到SQLite失敗的錯誤代碼?」這看起來像Java失敗而不是SQLite失敗,發佈所有LogCat錯誤。您使用的API是多少? – Sam
Unforutnately(或許幸運地)我不能再犯這個錯誤了。我拔掉了京瓷,並在連線7上工作了一段時間。當我回到京瓷,也許它做了一些更多的初始化(這是全新的)。任何我的應用程序成功創建其數據庫並跑。我希望我知道是什麼導致了失敗。也許我會嘗試重置工廠,看看有什麼功能。 –
好的,我做了一個工廠重置。再次嘗試失敗。然而,工廠重置並沒有清除SD卡(使我的數據庫保持完好),這可能會影響行爲 - 您會看到日誌略有不同。 –