File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes Remove Button and Concurrent modification exception Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Reply Bookmark "Remove Button and Concurrent modification exception" Watch "Remove Button and Concurrent modification exception" New topic
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
    
    4
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
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Remove Button and Concurrent modification exception
 
Similar Threads
problem in html:image
remove space betwen two button
Submitting a form on pressing Enter key
commandbutton inside panelgroup dont work
GUI problem