Java-Gaming.org
Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
Featured games (78)
games approved by the League of Dukes
Games in Showcase (406)
games submitted by our members
Games in WIP (293)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Implementation java game with slick2d on website  (Read 168 times)
0 Members and 1 Guest are viewing this topic.
Offline lukasz978

JGO Visitor




« Posted 2012-12-12 12:11:16 »

I have problem with implementation game on website. I have tried to do like in this site : http://ninjacave.com/slickapplet

I'm receiving this error:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
ERROR:MainPackage.TGame
java.lang.InstantiationException: MainPackage.TGame
at java.lang.Class.newInstance0(Unknown Source)
at java.lang.Class.newInstance(Unknown Source)
at org.newdawn.slick.AppletGameContainer.init(AppletGameContainer.java:124)
at org.lwjgl.util.applet.AppletLoader.switchApplet(AppletLoader.java:766)
at org.lwjgl.util.applet.AppletLoader.run(AppletLoader.java:644)
at java.lang.Thread.run(Unknown Source)
Fatal error occured (8): Unable to create game container
java.lang.RuntimeException: Unable to create game container
at org.newdawn.slick.AppletGameContainer.init(AppletGameContainer.java:148)
at org.lwjgl.util.applet.AppletLoader.switchApplet(AppletLoader.java:766)
at org.lwjgl.util.applet.AppletLoader.run(AppletLoader.java:644)
at java.lang.Thread.run(Unknown Source)


This is mine MainPackage.TGame
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
package MainPackage;
import org.newdawn.slick.*;
import org.newdawn.slick.state.*;

public class TGame extends StateBasedGame {

        public TotalPunkty suma = new TotalPunkty();
        public static final int menu = 0;
        public static final int game = 1;
        public static final int high = 2;
        public static final int about = 3;
        public static final int howto = 4;
        public static final int over = 5;

        BasicGameState G = new Game(game, suma);
        public BasicGameState O = new Over(over, suma);

        public static String title = "TGame";


        public TGame(String name) {
                super(name);
                this.addState(new Menu(menu));
                this.addState(G);
                this.addState(new High(high));
                this.addState(new About(about));
                this.addState(new HowTo(howto));
                this.addState(O);
        }


        public static void main(String[] args) throws SlickException {
                AppGameContainer MainWindow;

                try {
                        MainWindow = new AppGameContainer(new TGame(title));
                        MainWindow.setDisplayMode(800, 600, false);
                        MainWindow.setShowFPS(true);
                        MainWindow.setTargetFrameRate(60);
                        MainWindow.start();
                } catch(SlickException se) {
                        se.printStackTrace();
                }

        }

        public void initStatesList(GameContainer gc) throws SlickException {
                this.getState(menu).init(gc, this);
                this.getState(game).init(gc, this);
                this.getState(high).init(gc, this);
                this.getState(about).init(gc, this);
                this.getState(howto).init(gc, this);
                this.getState(over).init(gc, this);
                this.enterState(menu);
        }

}

I would be grateful if anyone could help me or just give me some tips how to fix that. Smiley
Offline davedes
« Reply #1 - Posted 2012-12-12 20:11:39 »

You are using AppGameContainer (i.e. desktop) when you should be using AppletGameContainer (i.e. web).

I'm also not sure where you learned to write code like that, but it does not use Slick correctly. Do not call init() on each state as the StateBasedGame will do that for you. See here.

Pages: [1]
  ignore  |  Print  
 
 

Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
 
Try the Free Demo of Revenge of the Titans

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

The invasion has landed! On Mars! And you're there to beat 'em!
cubemaster21 (84 views)
2013-05-17 21:29:12

alaslipknot (92 views)
2013-05-16 21:24:48

gouessej (123 views)
2013-05-16 00:53:38

gouessej (117 views)
2013-05-16 00:17:58

theagentd (127 views)
2013-05-15 15:01:13

theagentd (114 views)
2013-05-15 15:00:54

StreetDoggy (158 views)
2013-05-14 15:56:26

kutucuk (180 views)
2013-05-12 17:10:36

kutucuk (180 views)
2013-05-12 15:36:09

UnluckyDevil (187 views)
2013-05-12 05:09:57
Complex number cookbook
by Roquen
2013-04-24 12:47:31

2D Dynamic Lighting
by Oskuro
2013-04-17 16:46:12

2D Dynamic Lighting
by Oskuro
2013-04-17 16:45:57

2D Dynamic Lighting
by Oskuro
2013-04-17 16:23:20

Noise (bandpassed white)
by Roquen
2013-04-05 17:36:01

Noise (bandpassed white)
by Roquen
2013-04-03 16:17:38

Java Data structures
by Roquen
2013-03-29 13:21:12

Topic Request
by kutucuk
2013-03-22 21:42:01
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!
Page created in 0.216 seconds with 20 queries.