So, I was making a game state system, and came to this:
Exception in thread "main" java.lang.NullPointerException
at com.wessles.MERCury.StateCore.addState(StateCore.java:53)
at com.wessles.horde.Horde.init(Horde.java:46)
at com.wessles.MERCury.Runner.boot(Runner.java:43)
at com.wessles.MERCury.Core.<init>(Core.java:39)
at com.wessles.MERCury.StateCore.<init>(StateCore.java:29)
at com.wessles.horde.Horde.<init>(Horde.java:34)
at com.wessles.horde.Horde.main(Horde.java:60)
I looked at the code, and for some reason this is null:
public void addState(GameState state) {
gamestates.put(states, state);
states++;
}
Even though I initialized gamestate on the class:
private HashMap<Integer, GameState> gamestates = new HashMap<Integer, GameState>();
So it was initialized, and yet it is null (I checked with (gamestates == null)).
Why?!
EDIT:
I know I could just check for null and then initialize it, but I NEED to know how this could happen.
Also:
Full code