在我的应用程序中,我正在锁定数据库。数据库被锁定getReadableDatabase()android
我尝试使用其他帖子提供的解决方案,但找不到合适的解决方案,这就是为什么我发布这个问题。
这里是的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;
}
请帮我在这。
你的解决方案似乎很好,让我使用它,并验证它是否解决了我的问题,但为+1的好信息在后:) – 2013-02-12 05:41:45