Note that there are some explanatory texts on larger screens.

plurals
  1. POProblems with ListIterator and Concurrent Modification Exception
    primarykey
    data
    text
    <p>I have two ArrayLists, each holding blocks of certain size: blockList, eraserList. Blocks are objects with two fields: start and end. I need to subtract one set of blocks from the other set of blocks. </p> <p>I must walk through the eraserList and "erase" blocks out of the blockList where they overlap. Thus my code looks like:</p> <pre><code> void eraseBlocks (Arrylist&lt;Blocks&gt; blockList, ArrayList&lt;Blocks&gt; eraserList) { ListIterator&lt;Blocks&gt; it = blockList.listIterator(); for (Blocks eraser: eraserList) { while (it.hasNext()) { Blocks block= it.next(); if ((eraser.start &lt;= block.start) &amp;&amp; (eraser.end &gt;= block.end)) blockList.remove(block); else if ((eraser.start &lt;= block.start) &amp;&amp; (eraser.end &lt; block.end)){ block.set(start, eraser.end); else if () { ... //more code for where the eraser partially erases the beginning, end, or splits the block //if statements call the .add(), .set(), and remove() methods on the blockList. ... } } } </code></pre> <p>I don't understand why I am getting a Concurrent Modification Exception. I never modify the eraserList. </p> <p>I am trying to modify the block object that is assigned in the "Block block = it.next();" statement. I am also modifying the blockList by removing or adding blocks to the list. I thought the whole point of the ListIterator was that it allowed you to modify, add, or subtract a list you are walking through.</p> <p>The Failure Trace points to the Blocks eraser = it.next(); as the line drawing the exception, but I don't know what that is telling me.</p> <p>Can anyone help me figure out what I am doing wrong?</p> <p>Thanks!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload