Android SQLiteDiskIOException:编译时发生磁盘I/O错误(代码1802)::PRAGMA journal\u模式

Android SQLiteDiskIOException:编译时发生磁盘I/O错误(代码1802)::PRAGMA journal\u模式,android,sqlite,Android,Sqlite,最近我遇到了一些更频繁的崩溃,我不知道如何重现或修复它们。这是最常出现的一个 Fatal Exception: java.lang.RuntimeException: Unable to create application com.myapp.MyApplication: android.database.sqlite.SQLiteDiskIOException: disk I/O error (code 1802): , while compiling: PRAGMA journal_mod

最近我遇到了一些更频繁的崩溃,我不知道如何重现或修复它们。这是最常出现的一个

Fatal Exception: java.lang.RuntimeException: Unable to create application com.myapp.MyApplication: android.database.sqlite.SQLiteDiskIOException: disk I/O error (code 1802): , while compiling: PRAGMA journal_mode
   at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5436)
   at android.app.ActivityThread.-wrap2(ActivityThread.java)
   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1546)
   at android.os.Handler.dispatchMessage(Handler.java:102)
   at android.os.Looper.loop(Looper.java:154)
   at android.app.ActivityThread.main(ActivityThread.java:6154)
   at java.lang.reflect.Method.invoke(Method.java)
   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:757)
Caused by android.database.sqlite.SQLiteDiskIOException: disk I/O error (code 1802): , while compiling: PRAGMA journal_mode
   at android.database.sqlite.SQLiteConnection.nativePrepareStatement(SQLiteConnection.java)
   at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:889)
   at android.database.sqlite.SQLiteConnection.executeForString(SQLiteConnection.java:634)
   at android.database.sqlite.SQLiteConnection.setJournalMode(SQLiteConnection.java:320)
   at android.database.sqlite.SQLiteConnection.setWalModeFromConfiguration(SQLiteConnection.java:294)
   at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:215)
   at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:193)
   at android.database.sqlite.SQLiteConnectionPool.openConnectionLocked(SQLiteConnectionPool.java:463)
   at android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:185)
   at android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:177)
   at android.database.sqlite.SQLiteDatabase.openInner(SQLiteDatabase.java:808)
   at android.database.sqlite.SQLiteDatabase.open(SQLiteDatabase.java:793)
   at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:696)
   at android.app.ContextImpl.openOrCreateDatabase(ContextImpl.java:680)
   at android.content.ContextWrapper.openOrCreateDatabase(ContextWrapper.java:289)
   at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:223)
   at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:163)
   at com.myapp.DBConnect.getInstance(DBConnect.java:202)
   at com.myapp.MyApplication.onCreate(MyApplication.java:66)
我尝试的每次搜索听起来都像是试图从不同线程打开数据库的问题。然而,我认为我有一个设置来避免这种情况,在helper类中使用一个静态方法来获取当前实例

private static DBConnect mInstance = null;
private static SQLiteDatabase db;

public static DBConnect getInstance(Context ctx) {
    if (mInstance == null) {
        mInstance = new DBConnect(ctx.getApplicationContext());
        db = mInstance.getWritableDatabase(); // this is line 202 in DBConnect.java
        // all methods in this class reference this db var to run database queries
    }
    return mInstance;
}
然后,无论我在哪里需要访问数据库,我都会使用以下行设置一个局部变量db:

// this is line 66 in MyApplication.java
DBConnect db = DBConnect.getInstance(this);
然后使用类似于
db.addItem()

它一直运行良好,我90%确信多个线程正在访问同一个表,而我从未见过崩溃。该应用程序有几个列表,这些列表在后台几个地方同步,最容易复制的是当应用程序首次启动时,它会执行这些列表的同步。同步时,用户可以查看不同的列表,加载每个列表是从数据库中选择其内容,可能是在后台同步过程中从相同的表中添加或删除项目时。我每天也有几百个活跃用户,在过去几个月里,我只见过15次这样的崩溃

另外,看到错误的第一行是
java.lang.RuntimeException:无法创建应用程序…
,用户第一次启动应用程序时似乎发生了这种情况?不确定此时可能已经有多个线程,除非用户已登录,否则没有后台进程运行

我还看到了由同一行引起的以下错误:

Failed to change locale for db '/data/user/0/com.myapp/databases/mydb' to 'en_US'.

我试着在我的手机上更改语言环境设置,重新安装应用程序,然后胡闹,看看我是否遇到了这个问题。我甚至尝试在使用其他语言环境安装后切换回英语,但无法重复此崩溃。我觉得它们可能有关联,因为它们似乎都是在启动时发生的。

在我的情况下,我没有授予运行时权限。我将数据库文件保存在外部存储器中,当请求权限时,我拒绝了它,但当允许权限时,它工作正常。在SDK版本>=23上,您必须授予运行时权限

“磁盘I/O错误”意味着闪存已损坏。因此,我可以对此做些什么,还是忽略它?这对我来说似乎很奇怪,因为我以前可能一个月见过一次,但在过去的2-3个月里,它在8个不同的用户之间发生了15次。我也看到了内存不足错误的增加,尽管我们的用户数量保持相对不变。