首页 > 解决方案 > 未找到 LWJGLException?

问题描述

所以,我第一次尝试使用 LWJGL。我正在使用 LWJGL 版本 2.9.1,因为这是我正在关注的教程中使用的。我使用以下引用的库设置了我的 Eclipse 项目:lwjgl_util.jar、lwjgl.jar 和 slick-util.jar。我还为 Windows 链接了所有必要的本机 .dll 文件。导致错误的文件包含以下代码:

package render;

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);
        } catch (LWJGLException e) {
            e.printStackTrace();
        }
        
        // tell opengl where to render game (use whole display)
        GL11.glViewport(0, 0, WIDTH, HEIGHT); 
        
    }
    
    public static void updateDisplay() {
        
        Display.sync(FPS_CAP); // ensures buttery smooth fps
        Display.update();
    }
    
    public static void closeDisplay() {
        Display.destroy();
    }
}

我在下面使用这个类:

package engineTester;

import org.lwjgl.opengl.Display;

import render.DisplayManager;

public class MainGameLoop {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        
        DisplayManager.createDisplay();
        
        // enter game loop until someone clicks the top right x button
        while (!Display.isCloseRequested()) {
            // game logic and rendering
            DisplayManager.updateDisplay();
            
        }
        
        DisplayManager.closeDisplay();
    }
}

当我尝试运行上述文件时,出现以下异常:

Exception in thread "main" java.lang.NoClassDefFoundError: org/lwjgl/LWJGLException
    at engineTester.MainGameLoop.main(MainGameLoop.java:12)
Caused by: java.lang.ClassNotFoundException: org.lwjgl.LWJGLException
    at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:636)
    at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:182)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:519)
    ... 1 more

有人可以解释我做错了什么吗?我按照本教程中的每个步骤设置项目https://www.youtube.com/watch?v=Jdkq-aSFEA0&t=0s。任何帮助深表感谢!

标签: javaeclipseopengllwjgl

解决方案


推荐阅读