-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);
}
3
  • 1
    Please research before posting to SO. This exact question with the same problem has been asked and answered many, many times on SO. Commented Apr 14, 2013 at 22:41
  • Sorry, I had sought, but had not found. Commented Apr 14, 2013 at 22:47
  • How did you search? Did you google "java fix concurrentmodificationexception" and read the results? Commented Apr 14, 2013 at 22:50

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, I had forgotten that could do that.
-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.

2 Comments

False, see other answer.
Not true, as @Reimeus correctly points out Iterator has a remove method.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.