android P 中的 sqlite 数据库错误 "no such table"
sqlite database error "no such table" in android P
我正在使用 SQLiteOpenHelper 从资产中读取数据库。它适用于所有 android 版本,但 android p .
这是我的 copyDataBase 函数:
private static void copyDataBase() throws IOException {
InputStream myInput = myContext.getAssets().open(DB_NAME);
String outFileName = DB_PATH + DB_NAME;
OutputStream myOutput = new FileOutputStream(outFileName);
byte[] buffer = new byte[1024];
int length;
while ((length = myInput.read(buffer))>0){
myOutput.write(buffer, 0, length);
}
myOutput.flush();
myOutput.close();
myInput.close();
SharedPreferences shData = myContext.getSharedPreferences("data", 0);
SharedPreferences.Editor editor = shData.edit();
editor.putBoolean("databaseIsOnMemory", true);
editor.commit();
}
我在这个函数中输入了一个日志,它确实通过了。
但我收到此错误:
android.database.sqlite.SQLiteException: no such table: irancell (code 1 SQLITE_ERROR)
这是我获取数据的方式:
c = myDataBase.query(true, Table_Name, new String[] {IDData,TextData},
null,null,null,null,null, null);
c.moveToFirst();
int i = 1;
while(!c.isAfterLast()){
list.add(new KharidBaste(c.getInt(0),c.getString(5)));
c.moveToNext();
i++;
}
错误在线:"c.moveToFirst();"
检查数据库中的 table 名称。它可能不同。请记住 table 名称区分大小写。例如,table name Employee 和 employee 不相同。所以检查 table 名称。
在您的 createDB 函数中,您必须在 this.getReadableDatabase()
之后添加 this.close()
this.getReadableDatabase();
this.close();
This link can help you
我正在使用 SQLiteOpenHelper 从资产中读取数据库。它适用于所有 android 版本,但 android p .
这是我的 copyDataBase 函数:
private static void copyDataBase() throws IOException {
InputStream myInput = myContext.getAssets().open(DB_NAME);
String outFileName = DB_PATH + DB_NAME;
OutputStream myOutput = new FileOutputStream(outFileName);
byte[] buffer = new byte[1024];
int length;
while ((length = myInput.read(buffer))>0){
myOutput.write(buffer, 0, length);
}
myOutput.flush();
myOutput.close();
myInput.close();
SharedPreferences shData = myContext.getSharedPreferences("data", 0);
SharedPreferences.Editor editor = shData.edit();
editor.putBoolean("databaseIsOnMemory", true);
editor.commit();
}
我在这个函数中输入了一个日志,它确实通过了。 但我收到此错误:
android.database.sqlite.SQLiteException: no such table: irancell (code 1 SQLITE_ERROR)
这是我获取数据的方式:
c = myDataBase.query(true, Table_Name, new String[] {IDData,TextData},
null,null,null,null,null, null);
c.moveToFirst();
int i = 1;
while(!c.isAfterLast()){
list.add(new KharidBaste(c.getInt(0),c.getString(5)));
c.moveToNext();
i++;
}
错误在线:"c.moveToFirst();"
检查数据库中的 table 名称。它可能不同。请记住 table 名称区分大小写。例如,table name Employee 和 employee 不相同。所以检查 table 名称。
在您的 createDB 函数中,您必须在 this.getReadableDatabase()
之后添加 this.close()this.getReadableDatabase();
this.close();
This link can help you