Android SQLiteDiskIOException in getReadableDatabase(), native_setLocale, SQLiteOpenHelper

感情迁移 提交于 2019-12-11 03:06:51

问题


Recently I've run into a problem connected with using SQLiteOpenHelper. Few users reported the error I can't reproduce:

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:1987)
at android.database.sqlite.SQLiteDatabase.<init>(SQLiteDatabase.java:1855)
at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:820)
at android.database.sqlite.SQLiteOpenHelper.getReadableDatabase(SQLiteOpenHelper.java:197)

My implementation goes:

public class SqliteDatabase extends SQLiteOpenHelper
{
    public SqliteDatabase(Context context, String dbName, int dbVersion)
    {
        super(context, dbName, null, dbVersion);
        this.context = context;
        this.dbName = dbName;
        this.dbVersion = dbVersion;
    }
    (...)
}

So nothing special here. The exception is thrown after getReadableDatabase() invocation, as visible in stack.

Note that this class is accesed by many threads, but the access is totally synchronized (locks + only one, the same class instance). The Application can be moved to sdcard (maybe that's the issue?).

Unfortunately I do not know on which device / Android version the problem occurs (platform: other in Google Play console), but after doing some googling I suspect it's Android v2.2.1.

Any ideas? I know that the problem is more-less common, but I have not found any solution yet...


回答1:


SQLiteDiskIOException is related to multiple access at the same time to your database, one thread tries to get the data while another is trying to insert data at the same time.

But sometimes if you are getting "disk I/O error" using the following as for DB_PATH seems to fix the problem:

Environment.getDataDirectory() + "/data/YOUR_APP_PACKAGE/databases/";

read this: Database handling stoped working on Android 2.2.1 (Desire HD 1.72.405.3)




回答2:


  1. This type of error occured mostly when you perform two operations at the same time.
  2. When you close or open database by mistake. For example, when close your database and then you fire your query.


来源:https://stackoverflow.com/questions/13975513/android-sqlitediskioexception-in-getreadabledatabase-native-setlocale-sqlite

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!