-2

I'm trying to fix this problem, but in any case I do does not fix. Could someone help me?

for(Iterator<Block> iterator = event.blockList().iterator(); iterator.hasNext();)
{
    Block b = iterator.next();

    if (((RegiaoCuboid) r).contains(b))
        event.blockList().remove(b);
}
Lucas Fernando
  • 344
  • 3
  • 11

2 Answers2

3

Remove using the iterator:

iterator.remove();

A ConcurrentModificationException is thrown when a collection changes in a manner which invalidates open iterators. In this case you are calling remove directly on the collection.

Reimeus
  • 158,255
  • 15
  • 216
  • 276
-2

You can't modify a List while iterating over it. I would suggest adding the Blocks you wish to remove to a new List, then iterating over that and removing them from the main one (EDIT: Or, do what the other person said). Additionally, if you're doing what I think you are, I would suggest asking further questions on the Bukkit Forums. This question is more general, but Bukkit-specific questions will be more easily answered by individuals who are familiar with the area.

Max Roncace
  • 1,277
  • 2
  • 15
  • 40