0

I have class named DatabaseHandler to connect my app into SQLite.

but sometimes my app stop cause of

`android.database.sqlite.SQLiteCantOpenDatabaseException: unable to open database file (code 14): , 
 while compiling: PRAGMA journal_mode`

or

`android.database.sqlite.SQLiteException: Failed to change locale for db '/data/data/info/databases/test' to 'en_GB'.`

here is my code:

DatabaseHandler.java

public class DatabaseHandler extends SQLiteOpenHelper {
public DatabaseHandler(Context contextt) {
        super(YourApplication.context, DATABASE_NAME, null, DATABASE_VERSION);
    }


    // Creating Tables
    public void onCreate(SQLiteDatabase db) {
        String CREATE_SmsS_TABLE2 = "CREATE TABLE IF NOT EXISTS `currentInfo` (" +
                "`id`    INTEGER PRIMARY KEY ," +
                "`phoneNumber`  varchar(20)" +
                ");";
        db.setLocale(Locale.getDefault());
        db.execSQL(CREATE_SmsS_TABLE2);
    }

public Boolean getCurrentPhoneNumber() {
        SQLiteDatabase db = this.getWritableDatabase(); //<<<<<<<<error point at this line

        String Query = "SELECT * FROM currentInfo WHERE id=1";
        Cursor cursor = db.rawQuery(Query, null);
        if (cursor.getCount() > 0) {
            cursor.close();
            db.close();
            return false;
        }
        cursor.close();
        db.close();
        return true;

    }
}

how to fix these problem?

i read this article but , it use openDatabase method. not this.getWritableDatabase();

tnx.

EDIT

its take longer to throw error, here is my log cat result (same error again):

10-16 12:35:29.130 20855-20872/? E/SQLiteLog: (284) automatic index on sqlite_sq_AEDBB560(STAT_DATA_ID)
10-16 12:35:29.134 20855-20872/? E/SQLiteLog: (284) automatic index on sqlite_sq_AEDBB4C0(STAT_DATA_ID)
10-16 12:35:32.534 28634-31233/? E/SQLiteLog: (14) cannot open file at line 30047 of [9491ba7d73]
10-16 12:35:32.534 28634-31233/? E/SQLiteLog: (14) os_unix.c:30047: (24) open(/data/data/info/databases/test-journal) - 
10-16 12:35:32.534 28634-31231/? E/SQLiteLog: (14) cannot open file at line 30047 of [9491ba7d73]
10-16 12:35:32.534 28634-31231/? E/SQLiteLog: (14) os_unix.c:30047: (24) open(/data/data/info/databases/test-journal) - 
10-16 12:35:32.534 28634-31231/? E/SQLiteLog: (14) cannot open file at line 30047 of [9491ba7d73]
10-16 12:35:32.534 28634-31231/? E/SQLiteLog: (14) os_unix.c:30047: (24) open(/data/data/info/databases/test-journal) - 
10-16 12:35:32.534 28634-31231/? E/SQLiteLog: (14) statement aborts at 1: [PRAGMA user_version;] unable to open database file
10-16 12:35:32.538 28634-31230/? E/SQLiteLog: (14) cannot open file at line 30047 of [9491ba7d73]
10-16 12:35:32.538 28634-31230/? E/SQLiteLog: (14) os_unix.c:30047: (24) open(/data/data/info/databases/test-journal) - 
10-16 12:35:32.543 28634-31234/? E/SQLiteLog: (14) cannot open file at line 30047 of [9491ba7d73]
10-16 12:35:32.543 28634-31234/? E/SQLiteLog: (14) os_unix.c:30047: (24) open(/data/data/info/databases/test-journal) - 
10-16 12:35:32.543 28634-31234/? E/SQLiteLog: (14) cannot open file at line 30047 of [9491ba7d73]
10-16 12:35:32.543 28634-31234/? E/SQLiteLog: (14) os_unix.c:30047: (24) open(/data/data/info/databases/test-journal) - 
10-16 12:35:32.543 28634-31234/? E/SQLiteLog: (14) statement aborts at 2: [CREATE TABLE IF NOT EXISTS android_metadata (locale TEXT)] unable to open database file
10-16 12:35:32.545 28634-31234/? E/SQLiteDatabase: Failed to open database '/data/data/info/databases/test'.
                                                   android.database.sqlite.SQLiteException: Failed to change locale for db '/data/data/info/databases/test' to 'en_GB'.

EDIT 2

Failed to open database '/data/data/info/databases/test'.
                                                 android.database.sqlite.SQLiteCantOpenDatabaseException: unable to open database file (code 14): , while compiling: PRAGMA journal_mode
                                                     at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
                                                     at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:895)
                                                     at android.database.sqlite.SQLiteConnection.executeForString(SQLiteConnection.java:640)
                                                     at android.database.sqlite.SQLiteConnection.setJournalMode(SQLiteConnection.java:326)
                                                     at android.database.sqlite.SQLiteConnection.setWalModeFromConfiguration(SQLiteConnection.java:300)
                                                     at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:221)
                                                     at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:199)
                                                     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:1167)
                                                     at android.content.ContextWrapper.openOrCreateDatabase(ContextWrapper.java:268)
                                                     at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:223)
                                                     at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:163)
Community
  • 1
  • 1
msDead
  • 35
  • 10
  • i think local db file CRUD locks somewhere in your other source code. – reinhard.lee Oct 16 '17 at 07:58
  • thanks for reply, as you see ,i always close cursor , is it possible to cause error again? – msDead Oct 16 '17 at 08:01
  • `android.database.sqlite.SQLiteException: Failed to change locale for db '/data/data/info/databases/test' to 'en_GB'.` caused by call db.setLocale() method. did you make Local Db file? – reinhard.lee Oct 16 '17 at 08:06
  • 1
    Try removing single quotes around table and column names in the Table create String, delete the App's data and try again. i.e use `String CREATE_SmsS_TABLE2 = "CREATE TABLE IF NOT EXISTS currentInfo (" + "id INTEGER PRIMARY KEY ," + "phoneNumber varchar(20)" + ");";` – MikeT Oct 16 '17 at 08:08
  • @reinhard.lee i removed it , still have same error – msDead Oct 16 '17 at 08:08
  • You should post the stacktrace from the log in full rather than just a snippet from the stacktrace. – MikeT Oct 16 '17 at 08:15
  • tnx @MikeT ,see edit part. – msDead Oct 16 '17 at 09:09
  • have a read of this [Why and Where to call setLocale](https://stackoverflow.com/questions/13720092/why-and-where-to-call-setlocale). Perhaps also this [RuntimeException Failed to change locale for db to 'en_US'](https://github.com/Raizlabs/DBFlow/issues/440) – MikeT Oct 16 '17 at 10:01
  • @MikeT , tnx for reply , i remove it but faced another error , see Edit 2 logcat – msDead Oct 16 '17 at 10:19
  • uhhm try changing `YourApplication.context` to `contextt` i.e. the context passed. – MikeT Oct 16 '17 at 10:26
  • have a read of [Exception For Sqlite Database Pragma?](https://stackoverflow.com/questions/26817098/exception-for-sqlite-database-pragma) and [Unable to open database file (code 14): , while compiling: PRAGMA journal_mode](https://www.google.com.au/search?source=hp&q=unable+to+open+database+file+%28code+14%29%3A+%2C+while+compiling%3A+PRAGMA+journal_mode&oq=unable+to+open+database+file+%28code+14%29%3A+%2C+while+compiling%3A+PRAGMA+journal_mode&gs_l=psy-ab.3..0.1289.1289.0.9019.2.1.0.0.0.0.253.253.2-1.1.0....0...1.1.64.psy-ab..1.1.252.0...0.5uhrDtyRvO0) – MikeT Oct 16 '17 at 10:31

0 Answers0