簡體   English   中英

OnePlus設備的Sqlite問題

[英]Sqlite Issues with OnePlus device

我們有一個使用SQLite進行某種形式的永久存儲的android應用。 sqlite代碼可在除Oneplus設備之外的所有設備上使用。 (我正在測試Oneplus 2 A2003)

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

android.database.sqlite.SQLiteException:沒有這樣的表:testtable(代碼1):,而在編譯時:INSERT INTO testtable(ID,CompletedOn,CreatedOn,Type,Pending,Priority,Attributes)VALUES(?,?,?,?, ?,?,?)

以下是用於開放數據庫的數據庫片段

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

甚至嘗試在打開時指定訪問權限,但沒有區別。 例如SQLiteDatabase.NO_LOCALIZED_COLLATORS | SQLiteDatabase.OPEN_READWRITE

任何幫助,將不勝感激。

檢查這個答案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();
    }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM