I am trying to use a get/set to set variables in one class, and access it in another, but I can't get it to work. It doesn't return null, but it returns a size of 0 on the line: ArrayList<Integer> sizes = handler.getSizes();
Here is where I call the mutator:
And here is my slightly edited TMXHandler.java file (irrelevant bits removed):
private ArrayList<Integer> sizes = new ArrayList<Integer>(); is instantiating a new instance of ArrayList and hence the sizes reference variable is not null and points to a valid ArrayList instance of size 0.
Assuming the line above is part of the class declaration and not present withing any method.
The nullpointer exception is because the ArrayList is null and doesn't reference any object. Your earlier code was correct as it would initialise the ArrayList before inserting the data into the list.
I think I havent understood your query correctly. Sorry for that.
Fiona Heiss wrote:I am trying to use a get/set to set variables in one class, and access it in another, but I can't get it to work.
Can you tell us what exactly isn't working? (Before you made the change I mentioned in my first reply).
Joined: Jan 02, 2013
OK. I am trying to call
in the method loadWorld(). I am doing this to use the variables from the TMXHandler.java class for the following line: