Search code examples
javarenderingslick2d

SlickUtil - NoClassDefFoundError when accessing API


When I try to do anything with SlickUtil, I get this error

Exception in thread "main" java.lang.NoClassDefFoundError: org/newdawn/slick/opengl/renderer/Renderer
    at org.newdawn.slick.TrueTypeFont.<clinit>(TrueTypeFont.java:28)
    at Text.init(Text.java:14)
    at Main.main(Main.java:78)
Caused by: java.lang.ClassNotFoundException: org.newdawn.slick.opengl.renderer.Renderer
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 3 more

Code

public static Font font;
public static TrueTypeFont uf;

public static void main (String[] args) {

    font = new Font("Times New Roman", Font.BOLD, 20);
    uf = new TrueTypeFont(font, true); // Throws the error

}

public static void render (String text) {

    uf.drawString(0, 0, text);

}

Why is this error being thrown, and what can I do about it?

Otherwise, is there a method to display 2D text with OpenGL without using SlickUtil?


Solution

  • Why is this error being thrown, and what can I do about it?

    It is being thrown because the JAR file containing that dependency is not on the runtime classpath. (Apparently, the JAR file was available when your application was compiled. If it wasn't, then the source code that refered to the class would not have compiled.)

    What you need to do is to find / identify the JAR file, and add it to the runtime classpath of your application.


    Is there a method to display 2D text with OpenGL without using SlickUtil?

    That is a request for us to find or recommend software for you. It is off-topic.

    And moot ... if you sort out the real problem with your classpaths.