我只是尝试以 READWRITE 模式打开数据库。我收到以下错误:“不是错误(代码 0):无法以读/写模式打开数据库。”当以相同的方式打开数据库时,但 READONLY 是有效的。在我的 3 台设备上,这不是以 READWRITE 方式打开的问题,但有 2 位用户报告了以下错误。
数据库存在于用户文件系统中。我用 file.exists() 检查这个 -> 确定。 db 文件在用户设备上是可读写的。我用 file.canWrite() 检查这个 -> ok。
dbfile 存储在 :
存储路径:/mnt/extSdCard/mypath/mydb.db
2014 年 3 月 9 日的新信息:这似乎只是 KitKat 4.4.2 中的一个问题。由于用户已更新到 4.4.2,他们遇到了这个问题。
我的代码:
public void onCreate(Bundle savedInstanceState) {
connectWriter(); // throws exception below.
public void connectWriter() {
chronica_connection_readwrite = SQLiteDatabase.openDatabase("MyPath", null, SQLiteDatabase.OPEN_READWRITE);
//chronica_connection_read.enableWriteAheadLogging();
}
异常报告:
java.lang.RuntimeException: Unable to start activity ComponentInfo{...}: android.database.sqlite.SQLiteException: not an error (code 0): Could not open the database in read/write mode.
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2282)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2340)
at android.app.ActivityThread.access$800(ActivityThread.java:157)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1247)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:157)
at android.app.ActivityThread.main(ActivityThread.java:5293)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.database.sqlite.SQLiteException: not an error (code 0): Could not open the database in read/write mode.
at android.database.sqlite.SQLiteConnection.nativeOpen(Native Method)
at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:342)
at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:232)
at android.database.sqlite.SQLiteConnectionPool.openConnectionLocked(SQLiteConnectionPool.java:515)
at android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:207)
at android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:178)
at android.database.sqlite.SQLiteDatabase.openInner(SQLiteDatabase.java:891)
at android.database.sqlite.SQLiteDatabase.open(SQLiteDatabase.java:859)
at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:696)
at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:671)
at myclass.connectWriter(ChronicBrowser.java:14286)
at myclass.LoadModule(ChronicBrowser.java:10792)
at myclass.onCreate(ChronicBrowser.java:761)
at android.app.Activity.performCreate(Activity.java:5389)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2246)
************ DEVICE INFORMATION ***********
Brand: samsung
Device: hlte
Model: SM-N9005
Id: KOT49H
Product: hltexx
************ FIRMWARE ************
SDK: 19
Release: 4.4.2
Incremental: N9005XXUENB7
最佳答案
关于android - 无法在特定设备上为 ReadWirte 打开数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22267861/