android.database.sqlite.SQLiteCantOpenDatabaseException: unknown error (code 14): Could not open database android.database.sqlite.SQLiteCantOpenDatabaseException: unknown error (code 14): Could not open database android android

android.database.sqlite.SQLiteCantOpenDatabaseException: unknown error (code 14): Could not open database


Add this permission to your project's AndroidManifest.xml file, in the manifest tag (which should be the top level tag).

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />


Replace the checkDataBase() code with the code below:

File dbFile = myContext.getDatabasePath(DB_NAME);return dbFile.exists();


You may face this issue if you are running your app on Android's Marshmallow or later version (API level 23 or greater), because of the new Real-time Permissions model introduced in this.

Beginning in Android 6.0 (API level 23), users grant permissions to apps while the app is running, not when they install the app. This approach streamlines the app install process, since the user does not need to grant permissions when they install or update the app.

For getting permissions at runtime, you will have to request the user. You can do that in following way.

First request for permissions.

String[] permissions = {Manifest.permission.WRITE_EXTERNAL_STORAGE};        requestPermissions(permissions, WRITE_REQUEST_CODE);

And then you can check the results in

@Overridepublic void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) {    switch (requestCode) {       case WRITE_REQUEST_CODE:         if(grantResults[0] == PackageManager.PERMISSION_GRANTED){           //Permission granted.           //Continue with writing files...         }       else{           //Permission denied.         }        break;    }}

Here is good learning source requesting-runtime-permissions-in-android-marshmallow/