我有一个名为DatabaseHandler
的类将我的应用程序连接到SQLite。
但有时我的应用停止
的原因`android.database.sqlite.SQLiteCantOpenDatabaseException: unable to open database file (code 14): ,
while compiling: PRAGMA journal_mode`
或
`android.database.sqlite.SQLiteException: Failed to change locale for db '/data/data/info/databases/test' to 'en_GB'.`
这是我的代码:
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;
}
}
如何解决这些问题?
我阅读了this文章但是,它使用openDatabase
方法。不是this.getWritableDatabase();
TNX。
修改
抛出错误需要更长的时间,这是我的log cat结果(同样的错误):
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'.
编辑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)