Beheben des Fehlers java.util.ConcurrentModificationException beim Durchlaufen der ArrayList

Ich versuche, meiner ArrayList ein neues Objekt hinzuzufügen, wenn es die Bedingung erfüllt. Aber es brachte mir diese ConcurrentModificationExeption, als ich versuchte, es auszuführen. Hoffe du könntest mir helfen:

<code>public void addTaskCollection(Task t){ 
    ListIterator<Task> iterator = this.taskCollection.listIterator();
    if(this.taskCollection.isEmpty())
        this.taskCollection.add(t);
    while (iterator.hasNext()){
        if(t.isOverlapped(iterator.next()))
            this.taskCollection.add(t);
    }    
}
</code>

Und hier ist der Ausnahmefehler

<code>Exception in thread "main" java.util.ConcurrentModificationException
at java.util.ArrayList$Itr.checkForComodification(ArrayList.java:819)
at java.util.ArrayList$Itr.next(ArrayList.java:791)
at Diary.addTaskCollection(Diary.java:36)
at Test.main(Test.java:50)
Java Result: 1
</code>

Antworten auf die Frage(4)

Ihre Antwort auf die Frage