1 回答

TA贡献1828条经验 获得超4个赞
使用增强的for循环,您在内部使用List对象的迭代器。
在迭代基础列表时,不允许对其进行修改。这就是ConcurrentModificationException您现在所经历的。
使用标准的for循环,并确保在删除元素以获取所需功能时正确移动索引,如下所示:
ArrayList<Rectangle> blocks = getBlock();
ArrayList<Rectangle> done = getDone();
outer: for(int i = 0; i < blocks.size(); ++i)
{
for(int j = 0; j < done.size(); ++j)
{
if(blocks.get(i).y == done.get(j).y + 40)
{
done.add(blocks.get(i));
blocks.remove(i);
--i; // Make sure you handle the change in index.
create();
continue outer; // Ugly solution, consider moving the logic of the inner for into an own method
}
}
}
添加回答
举报