I am working with single thread game, in Main class i have ArrayList to contain Bullet objects for attacking zombies. Each of frame of game i do loop like:
ArrayList<Bullet> bulletList;
for (Bullet iBullet : bulletList) {
iBullet.move();
iBullet.attack(bulletList);
}
In Bullet class, i wrote
public void attack(ArrayList<Bullet> bulletList) {
for (Zombies z : zombieList) {
if ( hit condition ) {
bulletList.remove(this); //problem here
return;
}
}
}
I got null error after first loop, seems bullet object had removed successfully from ArrayList and also made some confuses in loop of Main class.