1

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?

2 Answers 2

7
private ArrayList<BlockObject> blocks = new ArrayList<BlockObject>();

You have to initialize your object.

Sign up to request clarification or add additional context in comments.

1 Comment

Oh man, that was blazing fast and amazingly easy. I am new to the language, very much appreciated
5

you have to initialize your arraylist before you populate it.

private ArrayList<BlockObject> blocks = new ArrayList<BlockObject>(); 

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.