This is my Bullets class
package mainPackage;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
public class Bullets {
private double x;
private double y;
private BufferedImage bulletImage;
Bullets(double x, double y){
this.x = x;
this.y = y;
ImageLoader loader = new ImageLoader();
SpriteSheet ss = new SpriteSheet(loader.loadImage("/Pics/TheSpriteSheet.png"));
bulletImage = ss.grabImage(2, 1, 32, 32);
}
public void render(Graphics g){
g.drawImage(bulletImage, (int)x, (int)y, null);
}
public void tick(){
y--;
}
public double getX(){
return x;
}
public double getY(){
return y;
}
}
Then I made my BulletQualities class
package mainPackage;
import java.awt.Graphics;
import java.util.LinkedList;
public class BulletQualities {
Bullets b;
private LinkedList<Bullets> bulletList = new LinkedList<Bullets>();
public void addBullet(Bullets b){
bulletList.add(b);
}
public void tick(){
I get an error on this next line
for(Bullets bullet:bulletList){
if(bullet.getY() == 0)
removeBullet(bullet);
bullet.tick();
}
}
public void render(Graphics g){
for(int x = 0;x < bulletList.size(); x++){
bulletList.get(x).render(g);
}
}
public void removeBullet(Bullets bullet){
bulletList.remove(bullet);
}
}
This is my error message:
Exception in thread "Thread-4" java.util.ConcurrentModificationException
at java.util.LinkedList$ListItr.checkForComodification(Unknown Source)
at java.util.LinkedList$ListItr.next(Unknown Source)
Then it just showed the lines with errors. I have no idea why It's not working. Please help me. It would mean a lot. :-)
Oh, I almost forgot, this is my removeBullet method from my bulletQualities class:
public void removeBullet(Bullets bullet){
bulletList.remove(bullet);
}