GRRR java errors

Started by
5 comments, last by ndssia 11 years, 7 months ago
I am attempting to make a pong clone but java hates me. I have these errors: Game.render() failure - check the game code, so i checked my code and i cant find anything wrong with it. now its just says in game.render() but there is no game.render(), however these are the two render methods with code in them. i have thwo others but they are empty:

public void render(GameContainer gc, StateBasedGame sbg, Graphics g) throws SlickException{
Image mainMenuScreen = new Image("res/MainMenu.png");
Image playButton = new Image("res/playButton.png");
Image exitButton = new Image("res/ExitButton.png");

g.drawImage(mainMenuScreen, 0,0);
g.drawImage(playButton, 500, 220);
g.drawImage(exitButton, 500, 300);
}

now i have this code in another class:

Image play = new Image("res/Play.png");
Image Paddle1 = new Image("res/Paddle.png");
Image Paddle2 = new Image("res/Paddle.png");

g.drawImage(play,0,0);
g.drawImage(Paddle1,0,200);
g.drawImage(Paddle2,620,200);


this is my Game.java class:

package MyGame;
import org.newdawn.slick.*;
import org.newdawn.slick.state.*;
public class Game extends StateBasedGame{
public static final String gamename = "Pong v.1";
public static final int mainmenu = 0;
public static final int play = 1;
public static final int menu = 2;
public static final int verdict = 3;

public Game(String gamename){
super(gamename);
this.addState(new MainMenu(mainmenu));
this.addState(new Play(play));
this.addState(new Menu(menu));
this.addState(new Verdict(verdict));
}

public void initStatesList(GameContainer gc) throws SlickException{
this.getState(mainmenu).init(gc, this);
this.getState(play).init(gc, this);
this.getState(menu).init(gc, this);
this.getState(verdict).init(gc, this);
this.enterState(mainmenu);
}

public static void main(String[] args) {
AppGameContainer appgc;

try{
appgc = new AppGameContainer(new Game(gamename));
appgc.setDisplayMode(680, 400, false); //Width length fullscreen
appgc.start();
}catch(SlickException e){
e.printStackTrace();
}

}
}

The screen shows up but in about 5 sec it closes.
Advertisement

I have these errors: Game.render() failure - check the game code
[/quote]
Is that literally the error message? Can you post the full error message, and any associated stack trace?


The screen shows up but in about 5 sec it closes.
[/quote]
Does it appear to work for those 5 seconds? You are creating new images every frame. If these images allocate system resources (which it appears to have, you have a resource leak that will eventually cause your program to fail. Try moving the images into fields, and only loading them once at startup. If possible, ensure you are loading each image exactly once.
Its says the time and date, but other than that it is the complete error message. And yes it works, i was trying to make it able to change the state when i click the button but it closes after 5 sec and wanted to get that fixed first.
Debug the application and tell us where exactly it crashes, what line etc and also the exception it throws + the printed call stack might be helpful as well.

BTW: put your code in so it gets formatted, otherwise it is a pain to read.
Project: Project
Setting fire to these damn cows one entry at a time!
So when i press f11 the program runs and then 3 sec later is stops. i am using eclipse btw, but in the consle window it shows this:
[source lang="java"]hu Aug 23 08:03:47 PDT 2012 INFO:Slick Build #274
Thu Aug 23 08:03:47 PDT 2012 INFO:LWJGL Version: 2.8.4
Thu Aug 23 08:03:47 PDT 2012 INFO:OriginalDisplayMode: 1280 x 1024 x 24 @50Hz
Thu Aug 23 08:03:47 PDT 2012 INFO:TargetDisplayMode: 680 x 400 x 0 @0Hz
Thu Aug 23 08:03:48 PDT 2012 INFO:Starting display 680x400
Thu Aug 23 08:03:48 PDT 2012 INFO:Use Java PNG Loader = true
Thu Aug 23 08:03:48 PDT 2012 INFO:Controllers not available
Thu Aug 23 08:03:50 PDT 2012 ERROR:Resource not found: res/MainMenu.png
java.lang.RuntimeException: Resource not found: res/MainMenu.png
at org.newdawn.slick.util.ResourceLoader.getResourceAsStream(ResourceLoader.java:69)
at org.newdawn.slick.opengl.InternalTextureLoader.getTexture(InternalTextureLoader.java:169)
at org.newdawn.slick.Image.<init>(Image.java:196)
at org.newdawn.slick.Image.<init>(Image.java:170)
at org.newdawn.slick.Image.<init>(Image.java:158)
at org.newdawn.slick.Image.<init>(Image.java:136)
at MyGame.MainMenu.render(MainMenu.java:18)
at org.newdawn.slick.state.StateBasedGame.render(StateBasedGame.java:199)
at org.newdawn.slick.GameContainer.updateAndRender(GameContainer.java:681)
at org.newdawn.slick.AppGameContainer.gameLoop(AppGameContainer.java:408)
at org.newdawn.slick.AppGameContainer.start(AppGameContainer.java:318)
at MyGame.Game.main(Game.java:36)
Thu Aug 23 08:03:50 PDT 2012 ERROR:Game.render() failure - check the game code.
org.newdawn.slick.SlickException: Game.render() failure - check the game code.
at org.newdawn.slick.GameContainer.updateAndRender(GameContainer.java:684)
at org.newdawn.slick.AppGameContainer.gameLoop(AppGameContainer.java:408)
at org.newdawn.slick.AppGameContainer.start(AppGameContainer.java:318)
at MyGame.Game.main(Game.java:36)
[/source]

and in the debug window it shows this:
[source lang="java"]<terminated>Game (1) [Java Application]
<terminated>MyGame.Game at localhost:48985
<terminated, exit value: 0>/usr/lib/jvm/java-6-openjdk-i386/bin/java (2012-08-23 8:03:47 AM)
[/source]
However i removed the big image and it worked. Im not sure how to set it as the background so i set it to 0,0. the image takes up the whole space. How would i set it as the background?

also im not sure how to do the grey bar sorry.
You can insert formatted code using [ code ] and [ /code ] tags (without the spaces). Also note that unless you followed my earlier advice about loading images during startup, you still have a resource leak.
Be careful what you put inside a draw/render loop; as stated above, you shouldn't be loading images in there.

Furthermode, it appears it can't find MainMenu.png, and throws an Exception, which leads to the top-level SlickException; that's your issue.

This topic is closed to new replies.

Advertisement