2016-01-04 35 views
1

我們有一個Android應用程序,它使用SQLite作爲某種形式的持久性存儲。 sqlite代碼適用於除Oneplus設備以外的所有設備。 (我正在測試Oneplus 2 A2003)Sqlite OnePlus設備問題

以下是我在logcat中看到的錯誤。

android.database.sqlite.SQLiteException:沒有這樣的表:TestTable的 (碼1):在編譯:INSERT INTO TestTable的(ID,CompletedOn,CreatedOn,類型,待處理,優先級,屬性) VALUES (?,?,?,?,?,?,?)

下面是用於打開數據庫這塊數據庫

SQLiteDatabase db = SQLiteDatabase.openDatabase(this.getHelperContext().getDatabasePath(DATABASE_NAME).getAbsolutePath(), null, 
        SQLiteDatabase.NO_LOCALIZED_COLLATORS); 

試過甚至規定而開放的訪問權限,但沒有d 。差分。 例如SQLiteDatabase.NO_LOCALIZED_COLLATORS | SQLiteDatabase.OPEN_READWRITE

任何幫助,將不勝感激。

+0

您是否正確創建數據庫?發佈你的onCreate和onUpdate。 – 323go

+0

卸載並重新安裝該應用程序,以確保您正在使用正確的數據庫架構,並且不會因架構版本號與您的onUpgrade()實現之間的不一致而中斷。或者,檢查現有數據庫的模式以查看它與所需模式之間的不同之處。 – CommonsWare

+0

數據庫模式(包含表格和示例數據)是應用程序的一部分,代碼只會嘗試讀取/更新/插入。 Oneplus 2設備唯一的一個問題,在休息狀態下工作正常(應用程序超過2年) –

回答

0

檢查答案https://stackoverflow.com/a/33032467/4504324它解決了我的問題。

只需關閉數據庫,然後將sqlite流複製到內部數據庫。

private void copyDataBase() throws IOException { 

    try { 
     //Open your local db as the input stream 
     InputStream myInput = mContext.getAssets().open("databases/" + DB_NAME+".sqlite"); 
     // Path to the just created empty db 
     String outFileName = mContext.getDatabasePath(DB_NAME).getAbsolutePath(); 

     //Open the empty db as the output stream 
     OutputStream myOutput = new FileOutputStream(outFileName); 

     //close the database so that stream can be copied 
     this.getReadableDatabase().close(); 

     //transfer bytes from the inputfile to the outputfile 
     byte[] buffer = new byte[1024]; 
     int length; 
     while ((length = myInput.read(buffer)) > 0) { 
      myOutput.write(buffer, 0, length); 
     } 
     //Close the streams 
     myOutput.flush(); 
     myOutput.close(); 
     myInput.close(); 
    } catch (Exception e) { 
     e.printStackTrace(); 
    } 
} 
+0

我在OnePus2上檢查了它,它工作正常。 –