Android - crash in for-each

view story

http://stackoverflow.com – I'm working on my first Android game. Objects are in a Vector and when I delete one of them in for-each loop, my game sometimes crashes. It doesn't if I break the loop, but I don't want to break because I need to check collision for every object. I have no idea what's wrong with my code. I would really appreciate your help :) for (Square s : level.squares) { if (s.moving) { s.pos.x += s.dir.x; s.pos.y += s.dir.y; for (Square sq : level.squares) { if (!sq.moving && s.pos.x == sq.pos.x && s.pos.y == sq.pos.y) { if (s.direction == sq.direction + 2 (HowTos)