Jump to content

  • Log In with Google      Sign In   
  • Create Account

We need your feedback on a survey! Each completed response supports our community and gives you a chance to win a $25 Amazon gift card!


GRRR java errors


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
6 replies to this topic

#1 Crusable   Members   -  Reputation: 594

Like
0Likes
Like

Posted 23 August 2012 - 07:14 AM

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.

Sponsor:

#2 rip-off   Moderators   -  Reputation: 8764

Like
0Likes
Like

Posted 23 August 2012 - 07:23 AM

I have these errors: Game.render() failure - check the game code

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.

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.

#3 Crusable   Members   -  Reputation: 594

Like
0Likes
Like

Posted 23 August 2012 - 07:34 AM

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.

Edited by Mathew Bergen, 23 August 2012 - 07:38 AM.


#4 Bluefirehawk   Crossbones+   -  Reputation: 1232

Like
0Likes
Like

Posted 23 August 2012 - 08:17 AM

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!

#5 Crusable   Members   -  Reputation: 594

Like
0Likes
Like

Posted 23 August 2012 - 09:08 AM

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 #274Thu Aug 23 08:03:47 PDT 2012 INFO:LWJGL Version: 2.8.4Thu Aug 23 08:03:47 PDT 2012 INFO:OriginalDisplayMode: 1280 x 1024 x 24 @50HzThu Aug 23 08:03:47 PDT 2012 INFO:TargetDisplayMode: 680 x 400 x 0 @0HzThu Aug 23 08:03:48 PDT 2012 INFO:Starting display 680x400Thu Aug 23 08:03:48 PDT 2012 INFO:Use Java PNG Loader = trueThu Aug 23 08:03:48 PDT 2012 INFO:Controllers not availableThu Aug 23 08:03:50 PDT 2012 ERROR:Resource not found: res/MainMenu.pngjava.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.

Edited by Mathew Bergen, 23 August 2012 - 09:09 AM.


#6 rip-off   Moderators   -  Reputation: 8764

Like
0Likes
Like

Posted 23 August 2012 - 09:24 AM

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.

#7 ndssia   Members   -  Reputation: 172

Like
0Likes
Like

Posted 23 August 2012 - 11:01 AM

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.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS