私のアプリでは、データベースがロックされています。
他の投稿で提供されている解決策を使用してみましたが、適切な解決策が見つからなかったため、この質問を投稿しています。
これがonCreateです
DBAdapter db = new DBAdapter(this.getApplicationContext());
dialoge = new Progress_Dialog(this);
dialoge.setCancelable(false);
try {
db.createDataBase();
} catch (IOException e) {
e.printStackTrace();
}
これがデータベース作成メソッドです
public void createDataBase() throws IOException{
boolean dbExist = checkDataBase();
if(!dbExist){
this.getReadableDatabase();
try {
copyDataBase();
} catch (IOException e) {
e.printStackTrace();
throw new Error("Error copying database");
}
}
}
以下はcheckdatabaseメソッドです
private boolean checkDataBase(){
SQLiteDatabase checkDB = null;
try{
String myPath = DB_PATH + DB_NAME;
String myPath2 = DB_PATH + DB_NAME2;
checkDB = SQLiteDatabase.openDatabase(myPath, null,
SQLiteDatabase.OPEN_READWRITE);
if(checkDB != null){
checkDB.close();
}
checkDB = SQLiteDatabase.openDatabase(myPath2, null,
SQLiteDatabase.OPEN_READWRITE);
}catch(SQLiteException e){
// e.printStackTrace();
//database does't exist yet.
System.out.print("SQLiteException "+e.toString());
}
if(checkDB != null){
checkDB.close();
}
return checkDB != null ? true : false;
}
これで私を助けてください。