android - android P中的sqlite数据库错误“没有这样的表”
问题描述
我使用 SQLiteOpenHelper 从 assets 中读取数据库。它适用于除 android p 之外的所有 android 版本。
这是我的 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();”
解决方案
在您的 createDB 函数中,您必须在 this.getReadableDatabase() 之后添加 this.close()
this.getReadableDatabase();
this.close();
推荐阅读
- python - 红点坐标检测
- python - 如何使用聚合 + Python 过滤数据
- api - 设置 Woocommerce 产品属性
- django-rest-framework - AttributeError:“collections.OrderedDict”对象没有属性“model_id”,可见字段中缺少“model_id”
- javascript - React:如何通过单击隐藏组件?
- node.js - 如何在不与客户端共享代码库的情况下在客户端服务器上运行我的 node.js 应用程序?
- cmake - cmake 可以在配置步骤中发出彩色输出吗?
- reactjs - 你能让 Heroku 根据移动/网络使用不同的代码吗?
- docker - Docker 容器中缺少端口
- python - 为没有 conda 的 macos 导入 openbabel 包装器 pybel