Can someone point out where im going wrong here please.
ive got my linked list populated with several objects, and im trying to move the selected object to the front of the list (or the back depending on which direction its supposed to go)
what i have so far is:
the error that it drops when this is called is:
java.util.ConcurrentModificationException
at java.util.LinkedList$ListItr.checkForComodification(LinkedList.java:552)
at java.util.LinkedList$ListItr.remove(LinkedList.java:521)
...
i have tried swapping the .remove and .addFirst/.addLast lines around but to no avail.
i have also tried .addFirst(it.next());/.addLast(it.next()); but not prospered there
the error seems to be in the .addFirst/.addLast line as if this is commented out, the object is removed, if i comment out the .remove() line the same error shows its face
any advice greatly appreciated
thanks in advance
I can't be bothered to have a sig!
ive got my linked list populated with several objects, and im trying to move the selected object to the front of the list (or the back depending on which direction its supposed to go)
what i have so far is:
Code:
public void toFront()
{
Iterator it = theObjects.iterator();
while (it.hasNext())
{
Object tmpObject = (Object)it.next();
if (tmpObject.isSelected())
{
theObjects.addFirst(tmpObject);
// theObjects.addLast(tmpObject); in toBack()
it.remove();
}
}
}
the error that it drops when this is called is:
java.util.ConcurrentModificationException
at java.util.LinkedList$ListItr.checkForComodification(LinkedList.java:552)
at java.util.LinkedList$ListItr.remove(LinkedList.java:521)
...
i have tried swapping the .remove and .addFirst/.addLast lines around but to no avail.
i have also tried .addFirst(it.next());/.addLast(it.next()); but not prospered there
the error seems to be in the .addFirst/.addLast line as if this is commented out, the object is removed, if i comment out the .remove() line the same error shows its face
any advice greatly appreciated
thanks in advance
I can't be bothered to have a sig!