Hello gamedev community, I need some help plz. This ConcurrentModificationException-error is making me crazy! I just recently started android game development and programming in general.
When i play my game its flawless but sometims if im trying to start a new game it crashes. Logcat show these two lines in my code but i dont know how to fix it because they look correct to me :/
public void run() {
while (playing) {
update();
draw(); //the draw-method is marked
control(); } }
and in my draw-method:
// I draw the SpaceDust from an ArrayList
paint.setColor(Color.argb(255, 255, 255, 255));
for (SpaceDust sd : dustList) {
canvas.drawPoint(sd.getX(), sd.getY(), paint); }
Logcat output:
FATAL EXCEPTION: Thread-146798
Process: niclas.spacegame, PID: 7983
java.util.ConcurrentModificationException
at java.util.ArrayList$ArrayListIterator.next(ArrayList.java:573)
at niclas.spacegame.TDView.draw(TDView.java:261)
at niclas.spacegame.TDView.run(TDView.java:174)
at java.lang.Thread.run(Thread.java:818)
Any ideas? Thanks Niclas