Sqlitediskioexception In Android
Solution 1:
It seems that you have multi threading issue, one thread tries to get the data while another one or more than one are trying to insert some data into your tables,because the exception is thrown from method (getCount).
Also don't forget; SQLite cursor is not internally synchronized, so if you use this cursor from multiple threads you should perform your own sync mechanism.
Solution 2:
We have similar problem. When our application starts souch error occurs. In onCreate method we check is there any database in application path. If any database occurs, we invoke such code
publicbooleancreateDataBase()throws IOException
{
booleandbExist= checkDataBase();
if(dbExist)
{
//do nothing - database already exist
}
else
{
//By calling this method and empty database will be created into the default system path//of your application so we are gonna be able to overwrite that database with our database.this.getReadableDatabase();
}
return dbExist;
}
privatebooleancheckDataBase()
{
SQLiteDatabasecheckDB=null;
try
{
StringmyPath= DATABASE_PATH + DATABASE_NAME;
checkDB = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READONLY);
}
catch(SQLiteException e)
{
}
if(checkDB != null)
{
checkDB.close();
}
return checkDB != null ? true : false;
}
And if there is no database(first run of application) we copy it from resources. But some times occurs SQLiteDiskIOException and database calls from resources.
Solution 3:
one reason is as Bassel Kh stated, multi thread problom, the another is the db is unavailable, ie. db is deleted or sdcard is unavaliable.
Post a Comment for "Sqlitediskioexception In Android"