Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9246451
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T09:29:31+00:00 2026-06-18T09:29:31+00:00

I am trying to use java slick to create a basic state based game.

  • 0

I am trying to use java slick to create a basic state based game. The 3 of my stages work fine, but for some reason the other 5 cause a null point exception when I call the get state method. All states are initialized and added to the game in the same manner, and the actual code for Load game (one of the working states) is exactly the same as all the broken ones, minus the class name. I have been looking over this for a day or so and have no idea, any help will be great. Thanks.

This is the code for my game class – containing my main method

package javagame.states;


import org.newdawn.slick.AppGameContainer;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.state.StateBasedGame;

public class Game extends StateBasedGame{

public static final String gamename = "An OOP Adventure";
public static final int menu = 0;
public static final int play = 1;
public static final int new_game = 2;
public static final int load_game = 3;
public static final int char_select = 4;
public static final int item_found = 5;
public static final int monster_fight = 6;
public static final int inventory = 7;



public Game(String gamename){
  super(gamename);
  this.addState(new Menu(menu));
  this.addState(new Play(play));
  this.addState(new Newgame(new_game));
  this.addState(new Loadgame(load_game));
  this.addState(new Charselect(char_select));
  this.addState(new Itemfound(item_found));
  this.addState(new Monsterfight(monster_fight));
  this.addState(new Inventory(inventory));

}
/*
 */
public void initStatesList(GameContainer gc) throws SlickException{
   this.getState(menu).init(gc, this);
   this.getState(play).init(gc, this);
   this.getState(load_game).init(gc, this);


   //broken states
   this.getState(new_game).init(gc, this);
   this.getState(item_found).init(gc, this);
   this.getState(char_select).init(gc, this);
   this.getState(monster_fight).init(gc, this);
   this.getState(inventory).init(gc, this);
   //end broken states
   this.enterState(menu);
}

public static void main(String[] args) {
   AppGameContainer appgc;
   try{
      appgc = new AppGameContainer(new Game(gamename));
      appgc.setDisplayMode(640, 360, false);
      appgc.start();
   }catch(SlickException e){
      e.printStackTrace();
   }
}

}

This is the code all the broken classes:

 package javagame.states;

 import org.newdawn.slick.GameContainer;
 import org.newdawn.slick.Graphics;
 import org.newdawn.slick.SlickException;
 import org.newdawn.slick.state.BasicGameState;
 import org.newdawn.slick.state.StateBasedGame;

 public class Newgame extends BasicGameState{


    public Newgame(int state){
    }

    public void init(GameContainer gc, StateBasedGame sbg) throws SlickException{

    }

    public void render(GameContainer gc, StateBasedGame sbg, Graphics g) throws SlickException{

    }

    public void update(GameContainer gc, StateBasedGame sbg, int delta) throws SlickException{

    }

    public int getID(){
       return 3;
    }
 }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T09:29:33+00:00Added an answer on June 18, 2026 at 9:29 am

    code for Load game (one of the working states) is exactly the same as all the broken ones, minus the class name

    all broken state classes and Loadgame class return getID() == 3.
    in Game constructor only Loadgame is registered as state with id == 3 – the others are ignored and thus never registered.
    then in initStatesList() other state classes cannot be found because there were no states registered with ids like 4, 5, 6, 7.

    fix all the broken state classes (including Loadgame) as follows:

    public class Newgame extends BasicGameState{
    private int state; // !!!

    public Newgame(int state){
        this.state = state; // !!!
    }
    
    ...
    
    public int getID(){
       return this.state; // !!!
    }
    

    }

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to use java to create HTTP requests, but I am getting
I'm trying to use Java ( not XML ) to create a LinearLayout with
I'm trying to use some Java-classes with Clojure. I've tried it with Scala with
I'm trying to get to use Nifty in my Slick game. However, i can't
I'm trying to use Java CertPathBuilder to create CertPath from user certificate and CA
I am trying to use Java Compiler API to compile some java class. That
I'm trying to use Java Applet for my website. but I have a problem
Trying to use a Java Enum in Jython but I can't figure out how
I'm trying to use the Java Robot class to do some automated testing for
Trying to use Java's regexp I want to match /app, /app/.* , but not

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.