Android的境界,我想這樣的代碼:Android的境界迭代例外
public void updateChecked(MyModel model) {
Realm.getDefaultInstance().beginTransaction();
model.setChecked(true);
Realm.getDefaultInstance().commitTransaction();
}
public void updateAllChecked() {
RealmResults<MyModel> results = Realm.getDefaultInstance().where(MyModel.class).findAll();
for (MyModel model : results) {
updateChecked(model);
}
}
與錯誤,當我打電話updateAllChecked():
java.util.ConcurrentModificationException: No outside changes to a Realm is allowed while iterating a RealmResults. Use iterators methods instead.
如何解決呢?
我用同樣的異常試過.. – ebnbin
@ebnbin,我已經更新了我的回答,對我的工作 – bananabastard
尼斯,它的作品!謝謝! – ebnbin