• Post Reply Bookmark Topic Watch Topic
  • New Topic

Concurent ModificationException

 
Sajay Narayan
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can anyone you help me on this runtine error

package polymorphismexamplepack;

import java.util.ArrayList;
import java.util.List;
import java.util.Collections;
import java.util.Iterator;
import java.util.ListIterator;

interface Shape{
double area(double d);
}


class Circle implements Shape{
double dim;
public double area(double d){
dim=d;
return (3.14*dim*dim);
}
}

class Square implements Shape{
double dim;
public double area(double d){
dim=d;
return (dim*dim);
}
}

/**
*
* @author temp
*/
public class ShapeMainClass {

/** Creates a new instance of ShapeMainClass */
public ShapeMainClass() {
}

/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
List listshape = new ArrayList();
Iterator itr = listshape.iterator();

Shape s = new Circle();
listshape.add(s);

double totarea=0;



s = new Square();
listshape.add(s);

while(itr.hasNext()){
s = (Shape)itr.next();
totarea+=s.area(5);
}


}

}
 
Chris Beckey
Ranch Hand
Posts: 116
Eclipse IDE Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please see: http://java.sun.com/j2se/1.5.0/docs/api/java/util/ConcurrentModificationException.html
hint: don't initialize the iterator until you actually need it.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!