4

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.

user1908860
  • 509
  • 1
  • 9
  • 19
  • Error Code 14 usually means the file is locked or blocked for some reason. Two questions -- are you using android:sharedUserId in your manifest? How are you assembly the path you are passing to the helper? This code may be invalid on Android 6.0. Can you post that part? – Cory Trese Oct 27 '15 at 03:24
  • I am not using sharedUsedId in mainfest. Added the code above. – user1908860 Oct 27 '15 at 05:18
  • Do you have the Write to External Storage permission in manifest? `` – Madhukar Hebbar Oct 27 '15 at 05:34
  • Possible duplicate of [android.database.sqlite.SQLiteCantOpenDatabaseException: unknown error (code 14): Could not open database](http://stackoverflow.com/questions/17034511/android-database-sqlite-sqlitecantopendatabaseexception-unknown-error-code-14) – Madhukar Hebbar Oct 27 '15 at 05:34
  • Yes i had added this permission. As i mentioned this has been working in all the devices since long. This problem starts happening only on a few devices which were upgraded to 6.0 (marshmallow). – user1908860 Nov 02 '15 at 20:25
  • @user1908860: did you find a fix for this problem. facing similar issues. Not exactly on Android 6,but on a few devices. On rest of the devices, it is working fine. – thedarkpassenger Feb 04 '16 at 13:11
  • @ user1908860 I'm also facing same issue on few devices (samsung tab A9)... did you found any solution for this ? Please let us know it will help others too..!! – Rahul Shirphule Nov 29 '16 at 14:51

1 Answers1

0

I yet meet the problem after add "android.permission.WRITE_EXTERNAL_STORAGE" permission in manifest, but still crashed like above.

FansLiu
  • 1
  • 4
  • Yeah. This has been working in all the devices since long. This problem starts happening only on a few devices which were upgraded to 6.0 (marshmallow). – user1908860 Nov 02 '15 at 20:25