java.util.ConcurrentModificationException problem

The error is in this part:

for (String s : tempFile){
    String [] splitted = s.split(" ");
    if (splitted[0].equals(naam)){
        tempFile.remove(s);
        found = true;   
    }
} 

Don't modify the list you are iterating over. You could solve this by using the Iterator explicitely:

for (Iterator<String> it = tempFile.iterator(); it.hasNext();) {
    String s = it.next();
    String [] splitted = s.split(" ");
    if (splitted[0].equals(naam)){
        it.remove();
        found = true;   
    }
} 

The Java 5 enhanced for loop uses an Iterator underneath. So When you remove from tempFile the fail fast nature kicks in and throws the Concurrent exception. Use an iterator and call its remove method, which will remove from the underlying Collection.

Tags:

Java

Exception