Alex Rivera | Logout

Java "ConcurrentModificationException" runtime error when iterating .next()

Asked 2011-02-28T18:39:17.157
10

According to the runtime error message the Exception occurs in the following line;

VirusData v = iteratorVirusDB.next();

VirusData is a class with a constructor and an overloaded constructor containing specific information about each of the viruses in the database such as;

  • String vName
  • String vDefinition

Overloaded with

  • Array with Tokenized definition (separated in groups of xLength)
  • Array with LCS Tokens
  • Float with a grade

iteratorVirusDB of type <VirusData> is an .iterator() of VirusDB, as shown bellow:

Iterator<VirusData> iteratorVirusDB = virusDB.iterator();

VirusDB is and ArrayList of type <VirusData> where I store the virus objects (name and def at this point) so that I can use them later.

ArrayList <VirusData> virusDB = new ArrayList<VirusData>();

And to end with, the error occurs in this method which uses all of the above explained:

private void selectDabataseMouseClicked(java.awt.event.MouseEvent evt) {
    while(iteratorVirusDB.hasNext()) {
        VirusData v = iteratorVirusDB.next();               //ERROR LINE
        String vSig = v.signature;                              
        v.tokens = tokenize.raw(vSig, true, tLength);
        ...
     }
     ...
}

I could really do with some help and advice on how to approach this problem in order to get get the program to run successfully. Bellow, the full StackTrace:

run:
Exception in thread "AWT-EventQueue-0" java.util.ConcurrentModificationException
        at java.util.AbstractList$Itr.checkForComodification(AbstractList.java:372)
        at java.util.AbstractList$Itr.next(AbstractList.java:343)
        at project_cle
Edit
Report

1 Answer

0

The concurrent modification exception occurs when you are modifying it while iterating over it at the same time. So check your code if you are modifying the list and it happens while you are iterating over it.

answered 2011-02-28T18:58:06.003

Your Answer