• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

ConcurrentModificationException

 
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
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

thanks in advance
 
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sure. I got an idea....but I won't disclose it because you haven't shown me your code.
 
tadi raja
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here is some part of the code

 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Maneesh Godbole
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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?
 
tadi raja
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't know exactly how to use a stack trace .. help me you have any idea ?
 
Maneesh Godbole
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Awesome.

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.
 
tadi raja
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here is the stack trace

 
Maneesh Godbole
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


This is what caused the exception.
Can you post that chunk of code?
 
tadi raja
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
here is the code ..


2)
 
Maneesh Godbole
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You have multiple mouse listeners for the same component?
 
tadi raja
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.

 
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
as a side note,
public void mouseClicked(MouseEvent e) {

never use mouseClicked(), it doesn't always fire.

more info in the apidocs
 
Rob Spoor
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
tadi raja
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
reply
    Bookmark Topic Watch Topic
  • New Topic