领域在更新ConcurrentModificationException
课程时抛出Model
。
java.util.ConcurrentModificationException: No outside changes to a Realm is allowed while iterating a RealmResults. Use iterators methods instead.
这是我的代码 -
Realm realm = Realm.getDefaultInstance();
RealmQuery<Model> query = realm.where(Model.class);
query.equalTo("decision", getString(android.R.string.yes));
ListIterator<Model> listIterator = query.findAll().listIterator();
realm.beginTransaction();
while (listIterator.hasNext()) {
Model model = listIterator.next();
model.setDecision(getString(android.R.string.no));
}
realm.commitTransaction();
答案 0 :(得分:2)
只需使用正常循环
realm.beginTransaction();
int size = results.size();
for (int i = size-1; i >= 0; i--) {
results.get(i).setDecision(getString(android.R.string.no));
}
realm.commitTransaction();