ok In the game thingy I made, its spawning new dudes every 5 seconds. It adds them to the array list of the corresponding team. I figured that, since it takes up a bit of processing power to constantly resize an arraylist, I should give them all a boolean value (dead), that the redering method checks for before painting them. However the new problem is that if the game goes on, said arrays will become filled with dead, and therefore useless, players. So every 30 seconds I made it so that it goes throught the array, and deletes the dead players. Now here is my problem, at seemeingly random checks, like it will successfully delete the dead once or maby ten times or maby more, it throws an arrray out of bounds error that refuses to be caught. I have no idea why it is doing this, because I ensure the capacity to like 50 for both arraylists too. Any one have an idea of what could cause this? The entire code is really long, but here is what causes the problem (bluep and redp are the arraylists, i.e. teams):
if((cc+600)%600==0)
{
System.out.println("Deleting the dead");
//System.out.println(bluep.size()+" "+redp.size());
try
{
int x,y;
for(x=0;x<bluep.size();++x)
{
BlueStick subb = (BlueStick)bluep.get(x);
if(subb.isDead()==true)
{
bluep.remove(x);
}
}
for(y=0;y<redp.size();++y)
{
RedStick subr = (RedStick)redp.get(y);
if(subr.isDead()==true)
{
redp.remove(y);
}
}
}
catch(IndexOutOfBoundsException e)
{
//System.out.println("x: "+x+" y: "+y);
System.out.println(bluep.size()+" "+redp.size());
}
}