I have a really weird problem that i am not able to reproduce neither on emulator or on any of the tested android devices.
I have a SQlite Database controller that holds all of mine data access functions, in this class i have a simple function to check if a table exists:
public boolean tableExists(String tableName) {
if(db==null || !db.isOpen()) db = dbhelper.getWritableDatabase();
Cursor cursor = db.rawQuery("SELECT name FROM sqlite_master WHERE type='table' AND name='"+tableName+"'", null);
if(cursor!=null) {
if(cursor.getCount()>0) {
cursor.close();
return true;
}
cursor.close();
}
return false;
}
On my application start i create an async task to check for updates and on this process i will check for the existence of a local table in the database.
The error thrown is on the Cursor cursor = db.rawQuery(... line, and the error is:
java.lang.IllegalStateException: database ... db.sqlite already closed
java.lang.RuntimeException: An error occured while executing doInBackground()
at android.os.AsyncTask$3.done(AsyncTask.java:200)
at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:274)
at java.util.concurrent.FutureTask.setException(FutureTask.java:125)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:308)
at java.util.concurrent.FutureTask.run(FutureTask.java:138)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1088)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:581)
at java.lang.Thread.run(Thread.java:1019)
Caused by: java.lang.IllegalStateException: database /data/data/com.xxx.xxx.xxx.android/databases/db.sqlite already closed
at android.database.sqlite.SQLiteCompiledSql.<init>(SQLiteCompiledSql.java:59)
at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:83)
at android.database.sqlite.SQLiteQuery.<init>(SQLiteQuery.java:49)
at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:42)
at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1364)
at android.database.sqlite.SQLiteDatabase.rawQuery(SQLiteDatabase.java:1332)
at com.xxx.xxx.xxx.utils.SQLiteController.tableExists(SQLiteController.java:1463)
I am not able to reproduce this error but according to ACRA this is happening several times in different devices.
Can someone give me a light on this?
Thanks.