【发布时间】:2017-09-26 00:20:09
【问题描述】:
我正在尝试将由 DB Browser for SQLite 创建的预加载 .db 文件复制到我在 Codename One 中制作的应用程序中。我已将应用程序放入我的 src 文件夹和 theme.res 文件夹(在 Data 下),并将以下代码添加到我的应用程序打开类的 init() 方法中:
String path = Display.getInstance().getDatabasePath("mydb.db");
Log.p("init path = " + path);
FileSystemStorage fs = FileSystemStorage.getInstance();
if(path != null && !fs.exists(path)) {
Log.p("path != null ");
try (OutputStream os = fs.openOutputStream(path);
InputStream is = Display.getInstance().getResourceAsStream(getClass(), "/mydb.db");
) {
Util.copy(is, os);
} catch (IOException err) {
Log.e(err);
//copyDb(path);
}
}
path返回一个变量。运行 模拟器 时,我收到以下错误消息:
java.sql.SQLException: [SQLITE_CORRUPT] The database disk image is malformed (database disk image is malformed)
在我的 Android 设备上,我收到以下消息:
Exception: android.database.sqlite.SQLiteException - no such table:
关于如何解决这个问题的任何想法?
谢谢!
【问题讨论】:
-
UCSConstantsAndCommons.DB&UCSConstantsAndCommons.DB_PATH的值是多少 -
"mydb.db" 和 "/mydb.db" 分别。我在上面做了这些更改。
标签: android ios sqlite codenameone