2

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...

bartull
  • 95
  • 1
  • 5

2 Answers2

0
  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.
Michael Irigoyen
  • 22,513
  • 17
  • 89
  • 131
QuokMoon
  • 4,387
  • 4
  • 26
  • 50
  • I looked through the code once again and indeed, there is small probability of concurrent access (no synchronized keyword on one of the methods). The probability of concurency is small, user has to enter application settings and tap "Clear cache" while service in the background is accessing database (it does it every 3 hours). But it could be the issue. Thanks. The second option is not possible in my case. – bartull Dec 20 '12 at 17:19
0

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)

Community
  • 1
  • 1
Jorgesys
  • 124,308
  • 23
  • 334
  • 268
  • Thank you. I've posted a comment about multiple access under Altaf's answer. As for the thread you posted, I've already read it, however I see no point in changing database path as I have not specified it...? – bartull Dec 20 '12 at 17:26