I have a simple arraylist set up, but I can't seem to add objects to it.
import java.util.ArrayList;
public class Inventory {
ArrayList inventory = new ArrayList();
String item1 = "Sword";
String item2 = "Potion";
String item3 = "Shield";
inventory.add(item1);
inventory.add(item2);
inventory.add(item3);
}
There are two errors, one at the dot between inventory and add, and one at the variable names between the brackets, being
Syntax error on token(s), misplaced construct(s)
and
Syntax error on token "item1", VariableDeclaratorId expected after this token
Can anyone explain why this is happening?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…