• Post Reply Bookmark Topic Watch Topic
  • New Topic

Remove Button and Concurrent modification exception  RSS feed

 
Jorge Bendahan
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 53779
128
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Rob Spoor
Sheriff
Posts: 20903
81
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!