My code to create a database in application class file is working on many thousands of devices but recently I got following crash, many times, all from android 6.0, so it may be related to the new android version. Also this crash was seen only on below given 3 devices. Please advise how to fix this..
Devices: Canvas A1 (AQ4501_sprout), Dream Uno (Mi-498_sprout), Sparkle V (Sparkle_V_sprout)
Crash log:
Caused by: android.database.sqlite.SQLiteCantOpenDatabaseException: unknown error (code 14): Could not open database
at android.database.sqlite.SQLiteConnection.nativeOpen(Native Method)
at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:207)
at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:191)
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:806)
at android.database.sqlite.SQLiteDatabase.open(SQLiteDatabase.java:791)
at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:694)
at android.app.ContextImpl.openOrCreateDatabase(ContextImpl.java:571)
at android.content.ContextWrapper.openOrCreateDatabase(ContextWrapper.java:269)
at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:223)
at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:163)
Reference code (Crash is happening at db.getWritableDatabase()) :
//Application class
public class MyApp extends Application {
@Override
public void onCreate() {
super.onCreate();
dataBaseInit();
}
private void dataBaseInit() {
db = new MyDatabase(getApplicationContext());
// This will open an reference to database
dataBaseRef = db.getWritableDatabase();
}
}
//Database class
public class MyDatabase extends SQLiteOpenHelper {
// All Static variables
// Database Version
private static final int DATABASE_VERSION = 1;
// Database Name
private static final String DATABASE_NAME = "myDatabase";
public MyDatabase(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
}
Crash is happening at db.getWritableDatabase().
Please advise how to fix this.