Я пытаюсь создать новую базу данных SQLite на устройстве.База данных выглядит «заблокированной» и выдает следующую ошибку:
13774-13774/com.example.dummy E/SQLiteLog: (5) database is locked
13774-13774/com.example.dummy E/SQLiteDatabase: Failed to open database '/data/data/com.example.dummy/databases/quizdb'.
android.database.sqlite.SQLiteDatabaseLockedException: database is locked (code 5): , while compiling: PRAGMA journal_mode
#################################################################
Error Code : 5 (SQLITE_BUSY)
Caused By : The database file is locked.
(database is locked (code 5): , while compiling: PRAGMA journal_mode)
Я удалил то, что я считаю нерелевантным кодом, чтобы оставить следующее:
class DbHelper extends SQLiteOpenHelper {
private static final String DB_NAME = "quizdb";
private static final int DB_VERSION = 301;
public DbHelper(Context context) {
super(context, DB_NAME, null, DB_VERSION);
}
@Override public void onCreate(SQLiteDatabase db) {
String omPath = Environment.getDataDirectory().getPath();
final String Path = omPath + "/data/com.example.dummy/databases/";
SQLiteDatabase gg = null;
try {
gg=SQLiteDatabase.openDatabase(Path + DB_NAME, null, 0);
} catch (Exception e){
//Database does not exist - need to create it
sqlQuery = String.format("CREATE TABLE IF NOT EXISTS %s ( %s INTEGER PRIMARY KEY AUTOINCREMENT, %s TEXT )", DB_TABLE, KEY_ID, KEY_QUES);
db.execSQL(sqlQuery);
addQuestions();
}
}
private void addQuestions() {
Question q1 = new Question("Question1234");
this.addQuestionToDB(q1, DB_TABLE);
}
private void addQuestionToDB(Question q, String DB) {
ContentValues values = new ContentValues();
values.put(KEY_QUES, q.getQuestion());
//Code fails on following line
dbase.insert(DB, null, values);
}