我在打开数据库时遇到问题,因为我的程序工作正常,但显示此错误。任何人都可以帮助我理解这一点。
这是我检查数据库存在于主
的方式private boolean checkDataBase(){
SQLiteDatabase checkDB = null;
try {
checkDB = SQLiteDatabase.openDatabase("Event.db", null, SQLiteDatabase.OPEN_READONLY);
checkDB.close();
}
catch (SQLiteException e) {
eventDB = new DatabaseEvent(this);
}
return checkDB != null;
}
我收到此错误我不知道如何解决?
E/SQLiteDatabase: Failed to open database 'MyACtion.db'.
android.database.sqlite.SQLiteCantOpenDatabaseException: unknown error (code 14): Could not open database
at android.database.sqlite.SQLiteConnection.nativeOpen(Native Method)
at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:209)
at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:193)
at android.database.sqlite.SQLiteConnectionPool.openConnectionLocked(SQLiteConnectionPool.java:463)
at android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:185)
at android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:177)
答案 0 :(得分:0)
在DatabaseEvent类的onCreate方法中,从以下位置更改SQL:
db.execSQL("CREATE TABLE... ;");
到
db.execSQL("CREATE TABLE... "); // NO SEMI-COLON
另外,在checkDataBase方法中,您没有打开在DatabaseEvent中创建的同一个数据库。而是致电:
DatabaseEvent db = new DatabaseEvent(context);
db.getReadableDatabase();