I am not using threads, but I keep getting an error saying:
"Exception in thread "AWT-EventQueue-0" java.util.ConcurrentModificationException"
Here is my code:
@Override
public void paint(Graphics g) {
for(Rectangles emp: shapes.list) {
//Loop through all rectangle objects
for(int[] temp: emp.arr) {
//Loop through each objects array
g.drawRect(temp[0], temp[1], 20, 20);
g.drawRect(20, 20, 20, 20);
}
}
}
There is also a method from a different class that executes very near the paint method, over and over again, which may be causing the problem.
public class Shapes {
LinkedList<Rectangles> list = new LinkedList<Rectangles>();
Random rand = new Random();
void newshape() {
int shape = rand.nextInt(7);
switch(shape) {
case 0:
list.add(makeSquare());
break;
case 1:
list.add(makeLine());
break;
case 2:
list.add(makeTShape());
break;
case 3:
list.add(makeLShape());
break;
case 4:
list.add(makeJShape());
break;
case 5:
list.add(makeZShape());
break;
case 6:
list.add(makeSShape());
break;
}
}
I am using the Notch game loop, with the tick() method calling the newshape() method if it has been one second since the last time a new shape was made. The paint method is then called.
public void run(Game game) {
while(true) {
lastshapemake = System.nanoTime();
long lastTime = System.nanoTime();
double Target_FPS = 60.0;
double ns = 1000000000 / Target_FPS;
double delta = 0;
while(running) {
long now = System.nanoTime();
delta += (now - lastTime) / ns;
lastTime = now;
while(delta >= 1) {
tick();
delta--;
}
if(running) {
game.repaint();
}
}
}
}