我无法在应用内部目录中打开数据库。我使用这段代码:
SQLiteDatabase db = SQLiteDatabase.openDatabase(appRootDir + "/dbname", null, SQLiteDatabase.OPEN_READWRITE);
当我运行此代码时,我收到此错误(这没有提示):
03-09 14:14:44.893: E/SQLiteLog(9604): (14) cannot open file at line 30279 of [00bb9c9ce4]
03-09 14:14:44.893: E/SQLiteLog(9604): (14) os_unix.c:30279: (13) open(/data/data/fido.contacts.merge/databases/contacts2.db) -
03-09 14:14:44.903: E/SQLiteDatabase(9604): Failed to open database '/data/data/fido.contacts.merge/databases/contacts2.db'.
03-09 14:14:44.903: E/SQLiteDatabase(9604): android.database.sqlite.SQLiteCantOpenDatabaseException: unknown error (code 14): Could not open database
03-09 14:14:44.903: E/SQLiteDatabase(9604): at android.database.sqlite.SQLiteConnection.nativeOpen(Native Method)
03-09 14:14:44.903: E/SQLiteDatabase(9604): at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:213)
03-09 14:14:44.903: E/SQLiteDatabase(9604): at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:197)
03-09 14:14:44.903: E/SQLiteDatabase(9604): at android.database.sqlite.SQLiteConnectionPool.openConnectionLocked(SQLiteConnectionPool.java:463)
03-09 14:14:44.903: E/SQLiteDatabase(9604): at android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:185)
03-09 14:14:44.903: E/SQLiteDatabase(9604): at android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:177)
03-09 14:14:44.903: E/SQLiteDatabase(9604): at android.database.sqlite.SQLiteDatabase.openInner(SQLiteDatabase.java:812)
03-09 14:14:44.903: E/SQLiteDatabase(9604): at android.database.sqlite.SQLiteDatabase.open(SQLiteDatabase.java:797)
03-09 14:14:44.903: E/SQLiteDatabase(9604): at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:702)
03-09 14:14:44.903: E/SQLiteDatabase(9604): at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:677)
03-09 14:14:44.903: E/SQLiteDatabase(9604): at fido.contacts.merge.RootManager.UnlockFacebookContacts(RootManager.java:121)
03-09 14:14:44.903: E/SQLiteDatabase(9604): at fido.contacts.merge.ui.OptionsActivity$1.onClick(OptionsActivity.java:87)
03-09 14:14:44.903: E/SQLiteDatabase(9604): at android.view.View.performClick(View.java:4128)
03-09 14:14:44.903: E/SQLiteDatabase(9604): at android.view.View$PerformClick.run(View.java:17142)
03-09 14:14:44.903: E/SQLiteDatabase(9604): at android.os.Handler.handleCallback(Handler.java:615)
03-09 14:14:44.903: E/SQLiteDatabase(9604): at android.os.Handler.dispatchMessage(Handler.java:92)
03-09 14:14:44.903: E/SQLiteDatabase(9604): at android.os.Looper.loop(Looper.java:213)
03-09 14:14:44.903: E/SQLiteDatabase(9604): at android.app.ActivityThread.main(ActivityThread.java:4787)
03-09 14:14:44.903: E/SQLiteDatabase(9604): at java.lang.reflect.Method.invokeNative(Native Method)
03-09 14:14:44.903: E/SQLiteDatabase(9604): at java.lang.reflect.Method.invoke(Method.java:511)
03-09 14:14:44.903: E/SQLiteDatabase(9604): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:809)
03-09 14:14:44.903: E/SQLiteDatabase(9604): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:576)
03-09 14:14:44.903: E/SQLiteDatabase(9604): at dalvik.system.NativeStart.main(Native Method)
03-09 14:14:44.903: W/System.err(9604): android.database.sqlite.SQLiteCantOpenDatabaseException: unknown error (code 14): Could not open database
03-09 14:14:44.913: W/System.err(9604): at android.database.sqlite.SQLiteConnection.nativeOpen(Native Method)
03-09 14:14:44.913: W/System.err(9604): at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:213)
03-09 14:14:44.913: W/System.err(9604): at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:197)
03-09 14:14:44.913: W/System.err(9604): at android.database.sqlite.SQLiteConnectionPool.openConnectionLocked(SQLiteConnectionPool.java:463)
03-09 14:14:44.913: W/System.err(9604): at android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:185)
03-09 14:14:44.913: W/System.err(9604): at android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:177)
03-09 14:14:44.913: W/System.err(9604): at android.database.sqlite.SQLiteDatabase.openInner(SQLiteDatabase.java:812)
03-09 14:14:44.913: W/System.err(9604): at android.database.sqlite.SQLiteDatabase.open(SQLiteDatabase.java:797)
03-09 14:14:44.913: W/System.err(9604): at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:702)
03-09 14:14:44.913: W/System.err(9604): at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:677)
03-09 14:14:44.913: W/System.err(9604): at fido.contacts.merge.RootManager.UnlockFacebookContacts(RootManager.java:121)
03-09 14:14:44.913: W/System.err(9604): at fido.contacts.merge.ui.OptionsActivity$1.onClick(OptionsActivity.java:87)
03-09 14:14:44.913: W/System.err(9604): at android.view.View.performClick(View.java:4128)
03-09 14:14:44.913: W/System.err(9604): at android.view.View$PerformClick.run(View.java:17142)
03-09 14:14:44.913: W/System.err(9604): at android.os.Handler.handleCallback(Handler.java:615)
03-09 14:14:44.913: W/System.err(9604): at android.os.Handler.dispatchMessage(Handler.java:92)
03-09 14:14:44.913: W/System.err(9604): at android.os.Looper.loop(Looper.java:213)
03-09 14:14:44.913: W/System.err(9604): at android.app.ActivityThread.main(ActivityThread.java:4787)
03-09 14:14:44.913: W/System.err(9604): at java.lang.reflect.Method.invokeNative(Native Method)
03-09 14:14:44.913: W/System.err(9604): at java.lang.reflect.Method.invoke(Method.java:511)
03-09 14:14:44.913: W/System.err(9604): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:809)
03-09 14:14:44.913: W/System.err(9604): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:576)
03-09 14:14:44.913: W/System.err(9604): at dalvik.system.NativeStart.main(Native Method)
通过相同的代码,我可以在外部目录中打开相同的数据库,如下所示:
SQLiteDatabase db = SQLiteDatabase.openDatabase(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS) + "/dbname", null, SQLiteDatabase.OPEN_READWRITE);
我也尝试在内部目录中打开一个像文件一样的数据库,以避免错误的路径或权限问题。我成功地运行了这段代码:
FileOutputStream fos = new FileOutputStream(new File(new File(appRootDir), "dbname"));
所以,我可以在外部目录中打开db,我可以像内部目录中的文件一样打开db,但是我不能像db一样在内部directrory中打开db。有什么想法吗?