這裏是我的代碼:與 「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