在我的应用程序中我得到数据库被锁定.
我尝试使用其他帖子中提供的解决方案,但找不到合适的解决方案,这就是我发布此问题的原因.
这是onCreate
DBAdapter db = new DBAdapter(this.getApplicationContext());
dialoge = new Progress_Dialog(this);
dialoge.setCancelable(false);
try {
db.createDataBase();
} catch (IOException e) {
e.printStackTrace();
}
Run Code Online (Sandbox Code Playgroud)
这是create database方法
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");
}
}
}
Run Code Online (Sandbox Code Playgroud)
以下是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;
}
Run Code Online (Sandbox Code Playgroud)
请帮帮我.
| 归档时间: |
|
| 查看次数: |
2398 次 |
| 最近记录: |