You declared the variable AL
inside the constructor (a local variable) and it is out of scope in the addInt
method.
Declare AL
outside of the constructor, but within the class. Also, use Integer
, not the primitive type int
for the generic type parameter. (Primitive types are not allowed as generic type parameters.)
public class Player
{
// Declare it here.
private ArrayList<Integer> AL;
public Player()
{
// Initialize it here.
AL = new ArrayList<Integer>();
}
// Now you can access `AL` in your methods.
public void addint(int C){
AL.add(C);
}
}