为什么没有sqlite错误代码

时间:2012-12-05 00:04:18

标签: android 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

1 个答案:

答案 0 :(得分:0)

嗯,这太愚蠢了。如果已连接设备并选择“USB存储”连接,则SD卡将无法访问。故事的道德:如果您的应用访问SD卡,请不要启用“USB存储”。

但是,Android应该发出错误代码 - 我会提交错误。