这里是我的代码:与 “java.util.ConcurrentModificationException” 卡壳
// eventList is a LinkedList
public void run() {
Iterator<Event> it = eventList.iterator();
int size = eventList.size();
while(size > 0) {
while(it.hasNext()) {
Event e = it.next(); //flaged line
if(e.ready()) {
System.out.println(e);
e.action();
eventList.remove(e);
--size;
}
}
}
}
错误java.util.ConcurrentModificationException
在林立的标志(Event e = it.next();
)被抛出。你是否看到我的代码中有一个错误,使得该异常被抛出的原因显而易见?
可能重复的[删除列表上的循环](http://stackoverflow.com/questions/1921104/loop-on-list-with-remove) – McDowell 2011-05-09 12:09:15