I got ConcurrentModificationException when right click(popup) on JList. When i am selecting (right click ) an item from the JList,popup appears. at the same time when i am selecting(right click) another item from the JList i got ConcurrentModificationException.how to solve this problem.any idea
JList uses a DefaultListModel by default, which uses a Vector in the background. That class will throw that exception if you are trying to modify it while iterating over it with a (List)Iterator.
The code you pasted most definitely should not cause any problems. The only odd thing is that you are calling SwingUtilities.invokeLater. That will execute the runnable in the Event Dispatcher Thread (EDT), but you're invoking it from that very same EDT.
Can you show us a) the exception stack trace, and b) the parts of your code where you modify the JList or its model?
tadi raja wrote:. When i am selecting (right click ) an item from the JList,popup appears. at the same time when i am selecting(right click) another item from the JList i got ConcurrentModificationException.
Usually, on a right handed mouse, you left click to select and right click for the context menu (popup). What is it in your case.
Like Rob said, the stack trace is your friend. That will tell you which line of your code is throwing the exception. Do you know how to use a stack trace?
You said you got a ConcurrentModificationException. Obviously your IDE/Logs/Console told you.
Copy paste that text here. Do not forget to use the code tags.
A stack trace, typically tells you what type of exception (with some additional information if available), the source file name and even the line number of that source file.
Looking at the line number, you can try and figure out which part of your code is causing problems.
Finally i got the solution .Thanks to Maneesh Godbole for his help .... in my code. Instead of implementing all the listeners in the MouseListener interface, i am using MouseAdapter class to implement a particular listener.
You do know that you can call addMouseListener multiple times, adding a mouse listener each time? It doesn't overwrite any previously added mouse listeners. As such, you don't have to handle multiple mouse listeners yourself.
I got ConcurrentModificationException everytime, that means right click on an item when popup displays at the same time when i left click on another item from the list. whenever i right click on an item from the list on the right to bring up a pop up window, then left click on a different item(not on the menu).previous solution was when i use MouseAdapter instead of MouseListener,the problem has been solved.but if i use mouseAdapter instead of MouseListener, lots of dependencies in my code has been corrupted.is there any better idea for this issue.
thanks in advance
So it takes a day for light to pass through this glass? So this was yesterday's tiny ad?
Free, earth friendly heat - from the CodeRanch trailboss