我们有一个Android应用程序,它使用SQLite作为某种形式的持久存储。 sqlite代码适用于除Oneplus设备之外的所有设备。 (我正在测试Oneplus 2 A2003)
以下是我在logcat中看到的错误。
android.database.sqlite.SQLiteException:没有这样的表:testtable (代码1):,编译时:INSERT INTO TestTable的(ID,CompletedOn,CreatedOn,类型,待处理,优先级,属性) 价值观(?,?,?,?,?,?,?)
以下是用于开放数据库的数据库
SQLiteDatabase db = SQLiteDatabase.openDatabase(this.getHelperContext().getDatabasePath(DATABASE_NAME).getAbsolutePath(), null,
SQLiteDatabase.NO_LOCALIZED_COLLATORS);
在打开时甚至尝试过指定访问权限,但没有区别。 例如SQLiteDatabase.NO_LOCALIZED_COLLATORS | SQLiteDatabase.OPEN_READWRITE
任何帮助都将不胜感激。
答案 0 :(得分: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();
}
}