Here is my code:
// 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;
}
}
}
}
The error java.util.ConcurrentModificationException
is thrown at the flag lined (Event e = it.next();
). Do you see a mistake in my code that makes obvious the reason of that exception to be thrown?