| Author |
Remove Button and Concurrent modification exception
|
Jorge Bendahan
Ranch Hand
Joined: Apr 11, 2008
Posts: 82
|
|
|
I'm getting this exception when deleting an item from any Jlist, Exception in thread "AWT-EventQueue-0" java.util.ConcurrentModificationException, i have a JButton "Remove", whenever i pressed this remove button, it enters into a method that iterates thru an ArrayList containing all the objects in the list, the exception is thrown but still the element gets removed. how can i solve this?.
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32644
|
|
Don't know. Sorry. What are you passing to the JList constructor? It takes an array, ListModel, or Vector, not an ArrayList directly. Why do you need an Iterator to remove it from the backing Collection? You can get the elementAt() or selectedElement() from a JLIst, but the API says it creates a read-only ListModel if you create the JList from an array or Vector. People might be better able to help with more details and a code snippet. [ June 23, 2008: Message edited by: Campbell Ritchie ]
|
 |
Maneesh Godbole
Saloon Keeper
Joined: Jul 26, 2007
Posts: 8433
|
|
Originally posted by Jorge Bend: .. iterates thru an ArrayList ... how can i solve this?.
Obtain the ListIterator (not Iterator) from the List and use the ListIterator#remove.
|
[Donate a pint, save a life!] [How to ask questions] [Onff-turn it on!]
|
 |
Rob Spoor
Sheriff
Joined: Oct 27, 2005
Posts: 19216
|
|
Originally posted by Maneesh Godbole: Obtain the ListIterator ( not Iterator) from the List and use the ListIterator#remove.
Good advice, except that remove is defined by Iterator, not ListIterator. So Jorge can keep on using Iterator, but just remove using that one:
|
SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
|
 |
 |
|
|
subject: Remove Button and Concurrent modification exception
|
|
|