I have one class that holds an ArrayList of an abstract class. Two different classes extend this abstract class. I fill the array with either one or the other of the two. The problem is, in an outside class when I set a reference to the object that contains the class holding the ArrayList, I cant access any instance variables from it.
If I check the ArrayList's size the size is holding the correct value, but displays null when I print out a value..
gives me null.. but it holds a value..
How do I access the values out of the ArrayList from another class properly?
Exactly as you are doing; it doesn't sound to me like that's your problem. The fact is that answer is null, not the ArrayList entry.
However, one tip I would give you is that stringing lots of derefs ('.') together can make things difficult to follow, so why not just break them up? viz:It may seem like a lot more code, but it'll help an awful lot in debugging.
Isn't it funny how there's always time and money enough to do it WRONG?
Joined: Feb 19, 2012
Thanks for the response Winston; I tried it the way you suggested and I still get a null print.. Guess I will just have to keep playing around with it.