3

I am trying to get Slick2d up and running in eclipse by following this tutorial. When I try and compile a test application I get the error:

Exception in thread "main" java.lang.NoClassDefFoundError: org/newdawn/slick/BasicGame
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClassCond(ClassLoader.java:631)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:615)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
    at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:247)

Any idea how to fix this?

wattostudios
  • 8,666
  • 13
  • 43
  • 57
user1150769
  • 395
  • 1
  • 4
  • 17

2 Answers2

3

The error basically indicates that it can't find at least one of the classes that are included in Slick. Sounds like you didn't add the Slick .JAR file to the proper place, or your classpath isn't set correctly. Double-check the settings where you include the Slick .JAR file in your project, and make sure that it's in the right place and setup properly.

There's a more verbose version of the setup guide in the official Slick Wiki.

jefflunt
  • 33,527
  • 7
  • 88
  • 126
0

The link in the above comment is no longer useful. Tried clicking on it, and it's gone. That's why it's best to explain things step by step inside of Stack Overflow's site.

You're build path is not set up correctly. What you need to do is

1) Make sure you have downloaded SLick2D jars from here:

Slick - Ninja Cave

2) Make sure you have downloaded LWJGL jars and natives from here:

LWJGL - Required Files Downloads Page

3) Right click your project, and go to Build Path -> Configure Build Path

4) Under the Source Tab, unfold the menu and go to the Native Library section. This needs to be set to the appropriate natives file in the LWJGL package. It's in a file called natives. Pick your OS, and continue.

5) Go to the Libraries Tab, and, if you have not done so, add the appropriate LWJGL jars, and the Slick jars. If you're smart, you'll create user libraries for both LWJGL and Slick2D for ease and future reuse. To create a user Library, simply click Add Library -> User library -> Add the jars you need for that library from an external location, I.E. the LWJGL download you have, in the jars file, and you're good to go.

Now, if you have configured everything okay, you're project should run. If not, it's not the build path, it's your code.

Hope this helps!