Ugh...

The tutorial is wrong (it's been updated now).
You should add states in initStatesList. After initStatesList is called, StateBasedGame will initialize all of them for you (so you shouldn't call state.init yourself!! otherwise they will be initialized twice). This means all of your states will be "initialized" at the beginning of your game.
If you don't want this, you can either add them to your game and manually initialize them
at some point after initStatesList... Or (preferred method) you can handle the initialization differently: subclass GameState and StateBasedGame and set up your own "activated" and "deactivated" methods that define when the state is first enetered, and then left. This way you can lazily load and destroy resources whenever the user enters/leaves states.
So, proper state initialization looks like this:
1 2 3 4
| public void initStatesList(GameContainer gameContainer) throws SlickException { this.addState(new MainMenuState(MAINMENUSTATE)); this.addState(new GameplayState(GAMEPLAYSTATE)); } |
And your constructor shouldn't have anything related to states:
By default, the first time you add a state in initStatesList it will be 'entered' (in this case main menu). So you could still use enterState after adding states, if you want to start with a different state.