| Author |
LinkedList and ConcurrentModification Exception problem
|
Branko Santo
Ranch Hand
Joined: Oct 15, 2005
Posts: 72
|
|
I am sorry to post such lengthy code but I just can't get it to work. I load up a LinkedList form disk and sort it and try to access the objects inside, but it throws the Exception. Really bummed I don't know what to do. I have bolded the trace to exception, any help would be great! Thanks!
|
 |
Jesper de Jong
Java Cowboy
Bartender
Joined: Aug 16, 2005
Posts: 12911
|
|
Do you understand what ConcurrentModificationException means? Look up the API documentation for it. You can't iterate over a List and modify the list at the same time. Instead of this: Try this, call remove() on the iterator instead of on the collection:
|
Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
|
 |
Ernest Friedman-Hill
author and iconoclast
Marshal
Joined: Jul 08, 2003
Posts: 24054
|
|
|
Don't use sezona.remove(game). Use iterator.remove() . Not only will the exception go away, but the performance will be much better for long lists. You can't call add() or remove() on a Collection while you're iterating over it, or the Iterator will throw an exception, as you found out.
|
[Jess in Action][AskingGoodQuestions]
|
 |
Anupam Bhatt
Ranch Hand
Joined: Mar 12, 2004
Posts: 81
|
|
Well that solves a frequently asked interview question too !
|
 |
Branko Santo
Ranch Hand
Joined: Oct 15, 2005
Posts: 72
|
|
Thanks people!!! I know what the exception did, but the problem is I saw no problem with the code I already had something like that, but it must be that last time I was using something like you did. Anyways really thanks!!! A million
|
 |
 |
|
|
subject: LinkedList and ConcurrentModification Exception problem
|
|
|