Results 1 to 6 of 6

Thread: ConcurrentModificationException in Collections

  1. #1
    Join Date
    Dec 2009
    Posts
    202

    ConcurrentModificationException in Collections

    Hello,
    I have an exceptional problem in fact I have a time, the first iteration step, but the exception is generated then I do not know how to turn. It comes when I have a array list of event listener that I travel with an iterator to dispatch messages (in fact there is only one listener) the work done by this listener is an update ui .. the first iteration has no problem all goes well in the second there is an exception type
    Code:
    java.util.ConcurrentModificationException
    that is generated. I read in the java doc for example, that this event was generated when a change was an item that is in an iterator but I do want to update my posting if you have a solution. I thank you for your help

  2. #2
    Join Date
    Nov 2009
    Posts
    335

    Re: ConcurrentModificationException in Collections

    Hello,
    You have access to 2 collections on your competitors. If you route your collection and at the same time you add it, delete or modify elements poses problem. What you can do is create a copy of your collection to browse and make true change in your collection. But no piece of code is hot to give you a solution. I think if you post your code then it can help us solve your problem.

  3. #3
    Join Date
    Nov 2009
    Posts
    583

    Re: ConcurrentModificationException in Collections

    Hey
    You can try the following code
    Code:
    Public  void  fireTreeChanged(TreePath loca){ 
       try { 
         List ls = Collections.synchronizedList(treeModelListeners);
         List lstc = new ArrayList();
         lstc.addAll(ls);
         synchronized(lstc){ 
           ListIterator it = lstc.ListIterator();
           Object t; 
           while (it.hasNext()) { 
             t = it.next(); 
             if (t instanceof TreeModelListener) {
               / / you recup the lstn from the real list            
               TreeModelListener lstn = (TreeModelListener) (ls.get(it.previousIndex() + 1));
               TreeModelEvent te = new TreeModelEvent(this, Loca);
               lstn.treeNodesChanged(te); 
             } 
             else { 
               / / System.out.println ( "ERROR OF CAST ModelPrincipal ln 94); 
             } 
           } 
         } 
       } catch (Exception ex) { 
         ex.printStackTrace(); 
       }

  4. #4
    Join Date
    Dec 2009
    Posts
    202

    Re: ConcurrentModificationException in Collections

    Hello,
    Here is my code, this is my updated code, see if you can identify the errors.
    Code:
    Public void addNoeud(TreePath lc, it new){
       try{
         it tp = (it) lc.getLastPathComponent();
         tp.AddModule(new);
         this.data2=this.rootit.getNivo(nivo);
         fireTableChanged();
         fireTreeChanged(lc);
       }catch(Exception e){
         System.out.System.out.println("exception"+ e);
       }
    / / FireTreeChanged (lc);
     }

  5. #5
    Join Date
    Nov 2009
    Posts
    347

    Re: ConcurrentModificationException in Collections

    Hello,
    The Vector class being synchronized, it might settle your problem without you I need to change anything.
    Otherwise you can try to do:
    Code:
    List ls = Collections.synchronizedList(tonArrayList);
    And use the object list to browse your ArrayList.

  6. #6
    Join Date
    Nov 2009
    Posts
    359

    Re: ConcurrentModificationException in Collections

    Hey,
    Alternatively you can try the following code:
    Code:
    while (iterator.hasNext()) { 
             t = iterator.next(); 
             if (t instanceof TreeModelListener) {  
               TreeModelListener lst = (TreeModelListener) t;
               TreeModelEvent te = new TreeModelEvent(this, Loca);
               lst.treeNodesChanged(te);

Similar Threads

  1. Is there any need of collections in Garden of Time
    By Jagjeet-J in forum Video Games
    Replies: 7
    Last Post: 24-12-2011, 05:47 AM
  2. Collections available in FrontierVille
    By Meditation in forum Video Games
    Replies: 4
    Last Post: 07-02-2011, 10:16 AM
  3. Collections in Java
    By blueprats in forum Guides & Tutorials
    Replies: 3
    Last Post: 22-03-2010, 02:51 PM
  4. Ordered index in Collections
    By Aaliya Seth in forum Software Development
    Replies: 5
    Last Post: 20-02-2010, 01:46 AM
  5. Collections in c#
    By Jagdish Gada in forum Software Development
    Replies: 5
    Last Post: 20-01-2010, 10:12 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,710,838,234.51085 seconds with 16 queries