0

我在开发者控制台中收到了这个崩溃报告:

java.lang.RuntimeException: Unable to start activity ComponentInfo{ZhuangDictActivity}: android.database.sqlite.SQLiteDiskIOException: disk I/O error
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1651)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
at android.app.ActivityThread.access$1500(ActivityThread.java:117)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3691)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:907)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:665)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.database.sqlite.SQLiteDiskIOException: disk I/O error
at android.database.sqlite.SQLiteDatabase.native_setLocale(Native Method)
at android.database.sqlite.SQLiteDatabase.setLocale(SQLiteDatabase.java:2144)
at android.database.sqlite.SQLiteDatabase.<init>(SQLiteDatabase.java:1996)
at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:905)
at android.database.sqlite.SQLiteDatabase.openOrCreateDatabase(SQLiteDatabase.java:995)
at android.database.sqlite.SQLiteDatabase.openOrCreateDatabase(SQLiteDatabase.java:988)
at DatabaseHelper.initDb(DatabaseHelper.java:79)
at ZhuangDictActivity.onCreate(ZhuangDictActivity.java:329)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1615)
... 11 more

这是导致问题的 DabaseHelper.java 的一部分:

public void initDb() {
    if (db != null) {
        db.close();
    }
    db = SQLiteDatabase.openOrCreateDatabase(ZhuangDictActivity.dbFile, null);
}

第 79 行是 db = SQLiteDatabase.openOrCreateDatabase(ZhuangDictActivity.dbFile, null) 导致问题的 ZhuangDictActiviy.java 部分:

if (dictName == null) {
} else {
    modifyDictVar(dictName);
    setTitle(loadDictInfo());

    initDbFile();
    databaseHelper.initDb();
}

第 329 行是 databaseHelper.initDb() ZhuangDictActivity.java 中抛出 IOException 的另一部分,我认为:

private void initDbFile() {
    dbFile = new File(dbFileName);
    if (!dbFile.exists()) {
        try {
            dbFile.createNewFile();
        } catch (IOException e) {
            showErrorDialog(getString(R.string.error));
            e.printStackTrace();
        }
    }
}

我的项目涉及将数据库写入外部存储。我应该如何解决这个问题?

4

1 回答 1

0

尝试

dbFile = Environment.getDataDirectory() + “/data/YOUR_PACKAGE/databases/”; 

另外,看看类似的答案

于 2013-10-21T03:04:29.340 回答