Slick Forums

Discuss the Slick 2D Library
It is currently Tue May 21, 2013 8:16 pm

All times are UTC




Post new topic Reply to topic  [ 6 posts ] 
Author Message
PostPosted: Sat Sep 26, 2009 6:46 pm 
Offline

Joined: Sat Sep 26, 2009 12:45 pm
Posts: 40
if anyone can help me get this sample code running i would much appreciate it thanks in advance. Ok B4 you flame me i should just let you know that i am new to java. when i read java code i can understand it and i can write it but when it comes to setting up the compiler am still learning.

I followed the instructions on this website http://www.gaanza.com/blog/tag/slick-2d-with-netbeans/ on how to get slick and netBeans setup i am very confident that i followed the instructions down to a T and that slick is working.
the problem am running into now is the last and final step, that is Step 8.
It says to "Create a new java project called SlickTest"
i did that, after i created the project i got a new editing window called Main.java
and here is whats in it.

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

package sllicktest;

/**
*
* @author Chalise
*/
public class Main {

/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
}

}


then it says to create a class called Test i did that and the following is whats in it.

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

/**
*
* @author Chalise
*/
public class Test {

}

Then they gave me the following code to test.

package com.padam.testing;

import org.newdawn.slick.AppGameContainer;
import org.newdawn.slick.BasicGame;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.SlickException;

/**
*
* @author padam
*/
public class Test extends BasicGame{

public Test(String name){
super(name);
}

public static void main(String[] args){
try {
AppGameContainer container = new AppGameContainer(new Test(”Game”));
container.setDisplayMode(800,600,false);
container.start();
} catch (SlickException e) {
e.printStackTrace();
}
}

@Override
public void init(GameContainer gc) throws SlickException {

}

@Override
public void update(GameContainer gc, int delta) throws SlickException {

}

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

}

}



It doesn't say to paste this code in Main.java or Test.java the class i just created. but i am assuming i have to paste the code inside my class and so here we go!


package com.padam.testing;

import org.newdawn.slick.AppGameContainer;
import org.newdawn.slick.BasicGame;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.SlickException;

/**
*
* @author padam
*/

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

/**
*
* @author Chalise
*/
public class Test {

public class Test extends BasicGame{

public Test(String name){
super(name);
}

public static void main(String[] args){
try {
AppGameContainer container = new AppGameContainer(new Test("Game"));
container.setDisplayMode(800,600,false);
container.start();
} catch (SlickException e) {
e.printStackTrace();
}
}

@Override
public void init(GameContainer gc) throws SlickException {

}

@Override
public void update(GameContainer gc, int delta) throws SlickException {

}

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

}

}

}

My problem lies here. when i try to build the program these are the errors i get.


C:\Users\Chalise\Documents\NetBeansProjects\SllickTest\src\Test.java:25: com.padam.testing.Test is already defined in com.padam.testing
public class Test extends BasicGame{
C:\Users\Chalise\Documents\NetBeansProjects\SllickTest\src\Test.java:33: non-static variable this cannot be referenced from a static context
AppGameContainer container = new AppGameContainer(new Test("Game"));
C:\Users\Chalise\Documents\NetBeansProjects\SllickTest\src\Test.java:31: inner classes cannot have static declarations
public static void main(String[] args){
3 errors
BUILD FAILED (total time: 0 seconds)

Does anybody have a clue as to what i need to do?


Top
 Profile  
 
 Post subject:
PostPosted: Sat Sep 26, 2009 6:59 pm 
Offline
Regular
User avatar

Joined: Thu Dec 18, 2008 6:07 pm
Posts: 238
Location: Bournemouth, UK
Quote:
/**
*
* @author Chalise
*/
public class Test {

public class Test extends BasicGame{


You've got "Test" class inside of "Test" class. (in Test.java)
You only need one of these!

So, remove "public class Test {", and don't forget to remove one "}" at the end.

_________________
- Gwinnell (irc.freenode.net, irc.chatspike.net)
- Game Jolt Moderator


Top
 Profile  
 
 Post subject: Thanks or the Help
PostPosted: Sat Sep 26, 2009 7:24 pm 
Offline

Joined: Sat Sep 26, 2009 12:45 pm
Posts: 40
now am getting the folloing error

java.lang.NoClassDefFoundError: Test
Caused by: java.lang.ClassNotFoundException: Test
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
Could not find the main class: Test. Program will exit.
Exception in thread "main"
Exception in thread "main" Java Result: 1
BUILD SUCCESSFUL (total time: 0 seconds)


Top
 Profile  
 
 Post subject:
PostPosted: Sun Sep 27, 2009 9:41 am 
Offline
Regular
User avatar

Joined: Thu Dec 18, 2008 6:07 pm
Posts: 238
Location: Bournemouth, UK
You'll still need...
public class Test extends BasicGame {

It's just that you had two of them.
If you are learning the java language, I recommend:
http://chortle.ccsu.edu/CS151/cs151java.html

_________________
- Gwinnell (irc.freenode.net, irc.chatspike.net)
- Game Jolt Moderator


Top
 Profile  
 
 Post subject:
PostPosted: Sun Sep 27, 2009 5:29 pm 
Offline

Joined: Fri Sep 25, 2009 7:12 pm
Posts: 3
Create a new project, and change Main.java to Game.java

then go here: http://slick.cokeandcode.com/wiki/doku.php?id=create_a_project_template and make your code match the code in there except for the package name, leave it to whatever NetBeans sets it to. Don't forget to make sure that your main function throws SlickException.

Also, the section entitled "Creating a template project" gives instructions on how to set up your libraries.

If you follow all these instructions, you'll have 1 class, and it will open a blank window with the Frame Rate showing in the top left corner.

I plan on adding pictures to the tutorial as soon as school lets out, which is in about a week. Hopefully this is enough until then.

_________________
Warning: This Signature removed a GameFAQs Moderator


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 30, 2009 12:41 pm 
Offline

Joined: Sat Sep 26, 2009 12:45 pm
Posts: 40
Thanks for the help everybody am good to go now!


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC


Who is online

Users browsing this forum: dayrinni and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group