Hello, I'm working on a project to perform a fast march algorithm in Java (finds the optimum path through a map from any point on the map to a goal) and I'm having a terrible old time trying to get my lists to be iterated correctly. I believe this is to do with the fact that I am attempting to alter the size of the list while I iterate it. I therefore thought I would have to use synchronised lists, which I am attempting to use but which don't change my runtime errors at all. Some example code of my problem I have listed below, the line where I get a java.util.ConcurrentModificationException is in bold. If I get this working I'll share the Fast March algorithim code here, I don't know if it's of any use to anyone, but it's an interesting piece of AI, anyway.
private java.util.List near;
private java.util.List far;
private java.util.List known;
terrain curr;
near = Collections.synchronizedList(new LinkedList());
far = new LinkedList();
known = new LinkedList();
curr =new terrain();
synchronized(near){
ListIterator linear = near.listIterator(0);
while ( linear.hasNext()) {
curr = (terrain)linear.next(); // selects item within the list being iterated
if(curr.pos.x != 0){
if(far.contains(map[curr.pos.x-1][curr.pos.y])){
near.add(map[curr.pos.x-1][curr.pos.y]);
far.remove(map[curr.pos.x-1][curr.pos.y]);
}
else if(known.contains(map[curr.pos.x-1][curr.pos.y])){
ux1= map[curr.pos.x-1][curr.pos.y];
}
}
//Bunch of other checks would go here, and a whole bunch
// of maths, and finally the slowness of curr would be
//known, and we'd add it to the known list...
known.add(curr);
}
}
}