2017-04-06 73 views
0

中打開數據庫異常我有問題了解打開數據庫時出現什麼錯誤,因爲我的程序工作正常,但它顯示此錯誤。任何人都可以幫助我理解這一點。無法在android

我這是怎麼檢查的主要

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

無我從常量接口 – mesa

回答

0

在DatabaseEvent類的onCreate方法改變來自SQL:

db.execSQL("CREATE TABLE... ;"); 

db.execSQL("CREATE TABLE... "); // NO SEMI-COLON 

也,你checkDataBase方法,你不打開同一個數據庫中你正在DatabaseEvent中創建。相反撥打:

DatabaseEvent db = new DatabaseEvent(context); 
db.getReadableDatabase(); 
+0

做我會嘗試感謝 – mesa

+0

我認爲getAllData方法()返回null即使這樣 – mesa

+0

後返回null而不是值? – mesa