-2
當我嘗試加載兩個文件時出現錯誤。 我的問題是如何將兩個json文件加載到領域。如何加載兩個json文件?
以下是加載JSON文件:
private void loadJsonFromStream() throws IOException {
InputStream stream = getAssets().open("school.json");
realm.beginTransaction();
try {
realm.createAllFromJson(School.class, stream);
realm.commitTransaction();
} catch (IOException e) {
// Remember to cancel the transaction if anything goes wrong.
realm.cancelTransaction();
} finally {
if (stream != null) {
stream.close();
}
}
}
被加載設置設置文件以下。
private void loadJsonSettingFromStream() throws IOException {
InputStream streamSetting = getAssets().open("setting.json");
realm.beginTransaction();
try {
realm.createAllFromJson(Setting.class, streamSetting);
realm.commitTransaction();
} catch (IOException e) {
// Remember to cancel the transaction if anything goes wrong.
realm.cancelTransaction();
} finally {
if (streamSetting != null) {
streamSetting.close();
}
}
顯示你的錯誤可能會讓別人給你更好的幫助。 – InbetweenWeekends