Advertisement

AppGameContainer problem

Started by May 03, 2015 01:25 PM
7 comments, last by Hannibal2400 9 years, 8 months ago

Hi,
I'm using Slick2D to make a game and i get an error when i try to run it, but eclipse is saying there is nothing wrong with my code and i just can't fix it by myself.
Here is the code:


package game;
import org.newdawn.slick.*;
import org.newdawn.slick.state.*;

public class Game extends StateBasedGame{

	public static final String frame_title = "Game";
	public static final int menu = 0;
	public static final int level_state = 1;
	public static int height = 630;
	public static int weight  = 360;
	
	public Game(String frame_title){
		super(frame_title);
		this.addState(new MenuState(menu));
		this.addState(new LevelState(level_state));
	}
	public void initStatesList(GameContainer game_container) throws SlickException{
		this.getState(menu);
		this.getState(level_state);
		this.enterState(menu);
	}
	public static void main(String[] args){
		AppGameContainer frame;
		try {
			frame = new AppGameContainer(new Game(frame_title));// here is the problem i think
			frame.setDisplayMode(height,weight,false);
			frame.start();
		}
		catch(SlickException error){
			error.printStackTrace();
	}

}
}

And the error:

x4q5js.png

Shouldn't your first two functions look like this?

public Game(String frame_title){
super(frame_title);
}

public void initStatesList(GameContainer game_container) throws SlickException{
this.addState(new MenuState(menu));
this.addState(new LevelState(level_state));
}

Why do you call getState() in initStatesList()?

Advertisement

Shouldn't your first two functions look like this?

public Game(String frame_title){
super(frame_title);
}

public void initStatesList(GameContainer game_container) throws SlickException{
this.addState(new MenuState(menu));
this.addState(new LevelState(level_state));
}

Why do you call getState() in initStatesList()?

With getState() in initStatesList() i initialise the state, and in the constructor i just create them. I'm not sure of it but that's how i find it in a tutorial. I don't think that is the problem but i shall try it like this :-??

Nope, as i expected, that has nothing to do with the problem.

getState() doesn't initialize state. addState() does. Here is an example from the Slick2D Wiki: http://slick.ninjacave.com/wiki/index.php?title=Game_States. Apart from that I don't see anything wrong. Are you sure you set up your project correctly? Seems like that might be the problem. Something with the LWJGL library. Did you add it?

getState() doesn't initialize state. addState() does. Here is an example from the Slick2D Wiki: http://slick.ninjacave.com/wiki/index.php?title=Game_States. Apart from that I don't see anything wrong. Are you sure you set up your project correctly? Seems like that might be the problem. Something with the LWJGL library. Did you add it?

Thanks for telling me that, but i think i did set it up the right way and i'm very sure i added LWJGL. I will try to make another project and see if i have any problems with it.

Advertisement

Still not fucking working...

With a new project, latest LWJGL and Slick3D releases and still not working. I can use Slick2D so i don't think i've set it up wrong, though i might be wrong.

Anyone else that can help me? Like this error is so uncommon no one knows how to fix it or what?:(

Ok so i fixed it!!!:D

The problem was that i was using the latest release of LWJGL and it seems like AppGameContainer doesn't work with it or has been changed to something else, i will look for the change. The fix is easy just download LWJGL 2 and use that instead of 3. Thanks for your help Hannibal2400! :P

Glad it works now. :)

This topic is closed to new replies.

Advertisement