我有一个 RealmResults<Section>
,其具有一个 RealmList<Event>
字段,我希望在每个 Section 上清除它。
我已经尝试过(在 mRealm.executeTransaction
内部):
for (Section section : mSections) {
section.getEvents().clear();
}
并且
Iterator<Section> sectionIterator = mSections.iterator();
while (sectionIterator.hasNext()) {
sectionIterator.next().getEvents().clear();
}
但是Realm会抛出这个异常
java.util.ConcurrentModificationException: 在遍历RealmResults时不允许对Realm进行外部更改。请使用迭代器方法。
getEvents()
返回什么?又是另一个ArrayList
吗? - Daniel NugentRealmList<Event>
,它基本上就像一个ArrayList。 - Ben