LibGDX 项目没有启动,它说无法初始化 class org.lwjgl.Sys

LibGDX project isn't launching, it says Could not initialize class org.lwjgl.Sys

每当我尝试启动一个 LibGDX 项目时,下面显示的问题不断出现:

Starting Gradle Daemon...
Gradle Daemon started in 2 s 577 ms
> Task :core:compileJava UP-TO-DATE
> Task :core:processResources NO-SOURCE
> Task :core:classes UP-TO-DATE
> Task :core:jar UP-TO-DATE
> Task :desktop:compileJava UP-TO-DATE
> Task :desktop:processResources UP-TO-DATE
> Task :desktop:classes UP-TO-DATE

> Task :desktop:DesktopLauncher.main()
[LwjglApplication] Couldn't initialize audio, disabling audio
java.lang.UnsatisfiedLinkError: /tmp/libgdxalice/dd5c1a65/liblwjgl64.so: /usr/lib/jvm/jdk-17/lib/libjawt.so: version `SUNWprivate_1.1' not found (required by /tmp/libgdxalice/dd5c1a65/liblwjgl64.so)
    at java.base/jdk.internal.loader.NativeLibraries.load(Native Method)
    at java.base/jdk.internal.loader.NativeLibraries$NativeLibraryImpl.open(NativeLibraries.java:388)
    at java.base/jdk.internal.loader.NativeLibraries.loadLibrary(NativeLibraries.java:232)
    at java.base/jdk.internal.loader.NativeLibraries.loadLibrary(NativeLibraries.java:174)
    at java.base/java.lang.ClassLoader.loadLibrary(ClassLoader.java:2389)
    at java.base/java.lang.Runtime.load0(Runtime.java:755)
    at java.base/java.lang.System.load(System.java:1953)
    at org.lwjgl.Sys.run(Sys.java:70)
    at java.base/java.security.AccessController.doPrivileged(AccessController.java:318)
    at org.lwjgl.Sys.doLoadLibrary(Sys.java:66)
    at org.lwjgl.Sys.loadLibrary(Sys.java:87)
    at org.lwjgl.Sys.<clinit>(Sys.java:117)
    at org.lwjgl.openal.AL.<clinit>(AL.java:59)
    at com.badlogic.gdx.backends.lwjgl.audio.OpenALLwjglAudio.<init>(OpenALLwjglAudio.java:72)
    at com.badlogic.gdx.backends.lwjgl.LwjglApplication.createAudio(LwjglApplication.java:282)
    at com.badlogic.gdx.backends.lwjgl.LwjglApplication.<init>(LwjglApplication.java:90)
    at com.badlogic.gdx.backends.lwjgl.LwjglApplication.<init>(LwjglApplication.java:71)
    at com.kuuject.atherwund.desktop.DesktopLauncher.main(DesktopLauncher.java:10)

BUILD SUCCESSFUL in 13s
5 actionable tasks: 1 executed, 4 up-to-date
Exception in thread "LWJGL Application" java.lang.NoClassDefFoundError: Could not initialize class org.lwjgl.Sys
    at org.lwjgl.opengl.Display.<clinit>(Display.java:135)
    at com.badlogic.gdx.backends.lwjgl.LwjglGraphics.setVSync(LwjglGraphics.java:643)
    at com.badlogic.gdx.backends.lwjgl.LwjglApplication.run(LwjglApplication.java:125)
9:18:30 AM: Execution finished ':desktop:DesktopLauncher.main()'.

我这辈子都想不出解决办法。起初,我尝试重新安装 JDK,但这根本不是问题所在。在我切换到 PopOS 之前,这不是问题。有帮助吗?

这是 LWJGL 的问题,而不是 LibGDX *nix 的问题。按照此处的说明进行操作

我发现了问题。您需要将 build.gradle 中的 LWJGL api 依赖项更改为 LWJGL3。

api "com.badlogicgames.gdx:gdx-backend-lwjgl:$gdxVersion"

api "com.badlogicgames.gdx:gdx-backend-lwjgl3:$gdxVersion"

在DesktopLauncher.java中,改变这些

import com.badlogic.gdx.backends.lwjgl.LwjglApplication;
import com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration;

LwjglApplicationConfiguration config = new LwjglApplicationConfiguration();
new LwjglApplication(new MyGdxGame(), config);

import com.badlogic.gdx.backends.lwjgl3.Lwjgl3Application;
import com.badlogic.gdx.backends.lwjgl3.Lwjgl3ApplicationConfiguration;

Lwjgl3ApplicationConfiguration config = new Lwjgl3ApplicationConfiguration();
new Lwjgl3Application(new MyGdxGame(), config);