Here’s a basic version of my Class “Power System”, I have cut most of the irrelevant code out.
Here I am adding Integers to an ArrayList, this works fine however when attempting to remove an object from the list
I get an error: “java.lang.IndexOutOfBoundsException: Index: 0, Size: 0” I am confused because this error is saying that my list contains nothing at index: 0 even though there is definitely an object or two in the list. I think this is all of the relevant code.
public ArrayList powers;
public void addPower(int id){
if(powers.size() < 3){
powers.add(id);
}
for(int i : powers){
System.out.println(i);
}
}
public void removePower(){
powers.remove(0);
}
public void useAbility(){
removePower();
}
public void tick(){ // I know I should be using an array or something here
if(!powers.isEmpty()){
currentPower = powers.get(0);
if(powers.size() == 2)
secondPower = powers.get(1);
if(powers.size() == 3)
thirdPower = powers.get(2);
}
}