-2

I got an error from google play. I want to stop the crash for user and just show him a message or a toast. app must keep going if this happens app should skip this or something. only some devices get this error.

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:2075)
at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:1014)
at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:986)
at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:962)
at offline.sinhaladic.com.MainActivity.searcc(MainActivity.java:1366)
at offline.sinhaladic.com.MainActivity$7.afterTextChanged(MainActivity.java:972)
at android.widget.TextView.sendAfterTextChanged(TextView.java:7678)
at android.widget.TextView$ChangeWatcher.afterTextChanged(TextView.java:8080)

this is my searcc function MainActivity.java:1366

public void searcc ()

  {               
      String myPath=Environment.getDataDirectory()+"/data/"+getPackageName()+"/"+"databases/cz";  
  EditText et=(EditText) findViewById(R.id.editText1);   
    SQLiteDatabase  cn = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READONLY);
      String cnql = "SELECT DISTINCT english FROM jgd INDEXED BY eng WHERE english LIKE '"+et.getText().toString()+"%' LIMIT 0,30";  
        Cursor cg=cn.rawQuery(cnql, null);      
            if(cg.moveToFirst())
          {
                do {                            
                         sugenstrArr.add(cg.getString(0));  
                } while (cg.moveToNext());                   
                }   

            cg.close();
            cn.close();             
    }
Jibran Khan
  • 3,236
  • 4
  • 37
  • 50
skk
  • 1
  • 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. referenced from http://stackoverflow.com/questions/13975513/android-sqlitediskioexception-in-getreadabledatabase-native-setlocale-sqlite – Jibran Khan Nov 08 '14 at 06:48
  • no, there is no insert in the code. just access read only. can you tell me how to try catch this or when got this error stop crash? – skk Nov 08 '14 at 06:50
  • check out the answer below by @almas shaikh – Jibran Khan Nov 08 '14 at 06:51

1 Answers1

0

Handle exception using try/catch block:

try {
    //do my sql stuff
} catch (SQLiteDiskIOException exception) {//or general like SQLiteException (which is not great)
    //handle your exception
}

So whenever your sql stuff is going to throw any exception, you would handle it (rather than propogating to caller method) and program will flow as normal it would (unless you re-throw the exception in catch block)

SMA
  • 36,381
  • 8
  • 49
  • 73