I had several glitches that appeared most often recently, and I cannot figure out how to reproduce or fix them. Here is the most common
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)
Every search I try to do sounds as if the problem is trying to open the database from different threads. However, I thought I had a setup to avoid this if the static method in the helper class should get the current instance.
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();
and then wherever I need to access the database, I have a local db variable set with this line:
// this is line 66 in MyApplication.java DBConnect db = DBConnect.getInstance(this);
then run all my database queries with features like db.addItem()
It works fine, and I'm 90% sure that multiple threads are accessing the same tables, that I have never seen crashes. The application has several lists that are synchronized in the background in several places, the easiest to play is when the application starts it first, these lists are synchronized. Although this is synchronization, the user can view different lists, downloading each list selects its contents from the database, possibly while items are added or deleted from the same tables in the background synchronization mode. I also have a couple of hundreds of active users per day, and over the past few months they have only seen this crash 15 times.
Also, seeing that the first line of the error is java.lang.RuntimeException: Unable to create application ... , it looks like this happens when the user first starts the application? Iβm not sure that at this stage there may already be several threads, none of the background processes are executed if the user has not logged in.
I also see the following error caused by the same line:
Failed to change locale for db '/data/user/0/com.myapp/databases/mydb' to 'en_US'.
I tried changing the locale settings on my phone, reinstalling the application, and then messing around to find out if I have this problem. I even tried to return to English after installation using a different language, but could not repeat this failure. I have a feeling that they can be connected, as they both seem to happen at startup.