The code is about a game in which you press a key and then the Enemy actor will be removed. I would like to use an ArrayList and put a bunch of the same Enemy actor inside so that all them are "numbered". When a key is pressed, the first item of that actor in the list will be removed.
This is how I create the Enemy object in the World in act().
This is where I want to remove the first object in the array when "1" is pressed and i++ so that it moved onto the next one.
When i run this, it says: java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
How do I fix that?
int random = Greenfoot.getRandomNumber(100); //lower the chance of the appearance of the Enemy
List<Enemy> ene = new ArrayList<Enemy>();
if(rand == 1)
{
eX = Greenfoot.getRandomNumber(460)+20;//choose a x location for the enemy randomly
enemy = new Enemy();
ene.add(enemy);
addObject(enemy, eX, 0);
}if(Greenfoot.isKeyDown("1"))
{
int i = 0;
removeObject(ene.get(i));
i++;
}

