ConcurrentModificationException in Java (Processing)
  Strange problem- I thought that by just making a new arrayList that I could avoid this error, yet for some reason its still throwing an exception with this code... any help? Thanks!


    ArrayList<Row> newrows = new ArrayList<Row>();
      
      
      for (Row i : rows) {

           newrows.add(i);
           Iterator iter = i.values.iterator();   //for each rect
        
                  while(iter.hasNext()) {
    
                      Rectangle value = (tree.Rectangle)iter.next();
                      if (!value.isLeaf) {
                        
        
                        Rectangle newChildRect = new Rectangle(value.children.get(0),
                                       dataTree.getAtomValue(value.children.get(0)));

                        Row newChildRow = new Row(value.start_x, value.start_y,
                                  value.rect_width, value.rect_height, newChildRect);

                        newrows.add(newChildRow);

                        squarify(newNewChildRow,          
                                   value.children.subList(1,value.children.size()));
                        
                        
                      }  
                      
                  }   
       } 
ConcurrentModificationException in Java (Processing)
===

  Strange problem- I thought that by just making a new arrayList that I could avoid this error, yet for some reason its still throwing an exception with this code... any help? Thanks!


    ArrayList<Row> newrows = new ArrayList<Row>();
      
      
      for (Row i : rows) {

           newrows.add(i);
           Iterator iter = i.values.iterator();   //for each rect
        
                  while(iter.hasNext()) {
    
                      Rectangle value = (tree.Rectangle)iter.next();
                      if (!value.isLeaf) {
                        
        
                        Rectangle newChildRect = new Rectangle(value.children.get(0),
                                       dataTree.getAtomValue(value.children.get(0)));

                        Row newChildRow = new Row(value.start_x, value.start_y,
                                  value.rect_width, value.rect_height, newChildRect);

                        newrows.add(newChildRow);

                        squarify(newNewChildRow,          
                                   value.children.subList(1,value.children.size()));
                        
                        
                      }  
                      
                  }   
       } 