public void execSqlFromAssets(String path) {
InputStream input;
String text;
try {
input = mCtx.getAssets().open(path + ".txt");
int size = input.available();
byte[] buffer = new byte[size];
input.read(buffer);
input.close();
text = new String(buffer);
String[] inserts = text.split(";");
// SQLiteDatabase db = mDb;
for (String insert : inserts) {
insert = insert;
Log.w(TAG, insert);
try {
mDb.execSQL(insert);
} catch (Exception e) {
String err = (e.getMessage() == null) ? "Cant execute sql"
+ insert : e.getMessage();
Log.w(TAG, err);
}
}
} catch (IOException e) {
Log.w(TAG, "execSqlFromAssets: " + path + " file not found");
}
}
这是我的代码问题在线包含mDb.execSQL(insert)。它抛出我无法读取的异常值为空。我只是不明白其中一条错误消息是: Cant execute sqlINSERT INTO food (name, cals) VALUES ("kolac",270)。任何帮助表示赞赏