Reputation: 9254
In my class I define:
private ArrayList<BlockObject> blocks;
And later:
blocks.add(new BlockObject(x, y));
However I get this error
02-22 17:06:52.672: E/AndroidRuntime(479): Caused by: java.lang.NullPointerException
02-22 17:06:52.672: E/AndroidRuntime(479): at com.comp1008.hhh.uuu.Scenario.blocks(Scenario.java:41)
Any suggestion?
Upvotes: 1
Views: 142
Reputation: 3015
private ArrayList<BlockObject> blocks = new ArrayList<BlockObject>();
You have to initialize your object.
Upvotes: 7
Reputation: 46408
you have to initialize your arraylist
before you populate it.
private ArrayList<BlockObject> blocks = new ArrayList<BlockObject>();
Upvotes: 5