• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

Remove Button and Concurrent modification exception

 
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?.
 
Marshal
Posts: 64710
226
  • 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 ]
 
Bartender
Posts: 11445
18
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • 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.
 
Sheriff
Posts: 21760
102
Eclipse IDE Spring VI Editor Chrome Java Ubuntu 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:
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!