I have a list. And I have declared it:
Then I tried to add an object to that list:
I'm not sure I'm doing it right but it always throws an exception no matter how. It was something like "Null pointer exception". Guess the List is still null, I don't have any idea how to instantiate it :/ Please help! Thanks anyway.
EDIT:
But this one doesn't throw error:
So I guess I need to do something before I add the object to the list but what?
That action is inside Unit class btw.
1 | private static List<Unit> AliveGroup; |
1 2 | if (AliveGroup == null || !AliveGroup.contains( this )) AliveGroup.add( this ); |
1 2 | if (AliveGroup == null || !AliveGroup.contains( this )) //AliveGroup.add(this); |