这是我在该网站上的第一篇文章。我在YouTube上关注着ThinMatrix的LWJGL 2游戏开发教程。我在其他帖子中看到了此错误,但是没有一个帮助。尝试运行时,出现此错误:
Exception in thread "main" java.lang.NoClassDefFoundError: org/lwjgl/LWJGLException
at engineTest.MainGameLoop.main(MainGameLoop.java:10)
Caused by: java.lang.ClassNotFoundException: org.lwjgl.LWJGLException
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:582)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:190)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:499)
... 1 more
代码使用LWJGL 2.9.3和slick-util库。我也在使用JavaSE 10(在本教程中他正在使用1.8,我不知道这是否重要)。错误指向我的主类中的第10行:
DisplayManager.createDisplay();
我将其余代码放在下面。我已经对教程进行了三遍检查,以使用正确的jar和本机来设置项目,并且已经被困了几个小时。任何帮助将不胜感激。
DisplayManager:
package renderEngine;
import org.lwjgl.LWJGLException;
import org.lwjgl.opengl.ContextAttribs;
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.DisplayMode;
import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.PixelFormat;
public class DisplayManager {
private static final int WIDTH = 1280;
private static final int HEIGHT = 720;
private static final int FPS_CAP = 120;
public static void createDisplay() {
ContextAttribs attribs = new ContextAttribs(3,2);
attribs.withForwardCompatible(true);
attribs.withProfileCore(true);
try {
Display.setDisplayMode(new DisplayMode(WIDTH, HEIGHT));
Display.create(new PixelFormat(), attribs);
Display.setTitle("Game");
} catch (LWJGLException e) {
e.printStackTrace();
}
GL11.glViewport(0, 0, WIDTH, HEIGHT);
}
public static void updateDisplay() {
Display.sync(FPS_CAP);
Display.update();
}
public static void closeDisplay() {
Display.destroy();
}
}
MainGameLoop:
package engineTest;
import org.lwjgl.opengl.Display;
import renderEngine.DisplayManager;
public class MainGameLoop {
public static void main(String[] args) {
DisplayManager.createDisplay();
while(!Display.isCloseRequested()) {
DisplayManager.updateDisplay();
}
DisplayManager.closeDisplay();
}
}