0
我試圖通過在MyApplication extends Application
中打開它並基本上從不關閉它來實現我的DatabaseInterface
實現(我做了一些研究,並由Google工程師推薦,請參閱鏈接問題Best place to close database connection)。我已經做了修改是非常小的,但現在系統拋出我打開數據庫時出現以下錯誤:從MyApplication打開SQLite數據庫 - 無法在讀/寫模式下打開
E/SQLiteDatabase(15690): android.database.sqlite.SQLiteException: not an error (code 0): Could not open the database in read/write mode.
下面是相關的代碼
MyApplication.java
@Override
public void onCreate() {
super.onCreate();
try {
DatabaseInterface.open();
} catch (SQLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
DatabaseInterface.java
public class DatabaseInterface extends SQLiteOpenHelper {
private final static String DB_PATH = Constants.DB_PATH;
private final static String DB_NAME = Constants.DB_NAME;
private static SQLiteDatabase mDatabase;
private Context mContext;
private static DatabaseInterface mInstance;
private DatabaseInterface(Context context) {
super(context, DB_NAME, null, 1);
this.mContext = context;
}
public static DatabaseInterface getInstance(Context context) {
if (mInstance == null) {
mInstance = new DatabaseInterface(context);
}
return mInstance;
}
public static void open() throws SQLException, IOException {
//Open the database
String path = DB_PATH + DB_NAME;
mDatabase = SQLiteDatabase.openOrCreateDatabase(new File(path), null);
}
}