Android SQLite database exception - code 14 (cannot open the database file)

I have a database problem in my android app. I get this exception in many places from different databases:

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.logtomobile.gmbclient/com.logtomobile.gmbclient.TransactionHistoryActivity}: android.database.sqlite.SQLiteCantOpenDatabaseException: unable to open database file (code 14)

All my databases use singleton classes that extend SQLiteOpenHelper. I also close all cursors after use. What could be the reason for such exceptions? What can I do to fix this?

Prior to this exception, I received another SQLite exception:

(14) cannot open file at line 32473 of [00bb9c9ce4]
(14) os_unix.c:32473: (24) open(/data/data/com.logtomobile.gmbclient/databases/GmbDB-journal) 

I cannot insert my code because this exception is thrown every time in another place in the code. All databases are created in code and are not imported from external files. All methods that cause database queries are called from synchronized methods in database helpers. Helpers have static instances of Helper (singleton), whitch also has SQLiteDatabase objects. These objects are initialized once in Helper constructors using getWritableDatabase () and are always saved without closing them. Each query in the code calls these SQLiteDatabase objects.

public synchronized static GmbDBHelper getInstance(Context context) {
    if (sHelper == null) {
        sHelper = new GmbDBHelper(context.getApplicationContext());
    }

    return sHelper;
}

private GmbDBHelper(Context context) {
    super(context, GmbDB.DB_NAME, null, DB_VERSION);

    mContext = context;
    mDatabase = getWritableDatabase();

    Log.d("DbHelper", "GmbDbHelper()");
}

synchronized SQLiteDatabase openDbForReading() {
    return mDatabase;
}

synchronized SQLiteDatabase openDbForWriting() {
    return mDatabase;
}

...
+4
source share
1 answer

Please check permissions in the manifest. And add the following just in case you missed.

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

All Articles