UnsatisfiedLinkError Libgdx 桌面

我在桌面上遇到了 LibGDX 的问题.尝试启动应用程序时,我不断收到以下错误:

I am running into issues with LibGDX on Desktop. I keep getting the following error when trying to launch the application:

Exception in thread "main" java.lang.UnsatisfiedLinkError: com.badlogic.gdx.utils.BufferUtils.newDisposableByteBuffer(I)Ljava/nio/ByteBuffer;
at com.badlogic.gdx.utils.BufferUtils.newDisposableByteBuffer(Native Method)
at com.badlogic.gdx.utils.BufferUtils.newUnsafeByteBuffer(BufferUtils.java:288)
at com.badlogic.gdx.graphics.glutils.VertexArray.<init>(VertexArray.java:62)
at com.badlogic.gdx.graphics.glutils.VertexArray.<init>(VertexArray.java:53)
at com.badlogic.gdx.graphics.Mesh.<init>(Mesh.java:148)
at com.badlogic.gdx.graphics.g2d.SpriteBatch.<init>(SpriteBatch.java:173)
at com.badlogic.gdx.graphics.g2d.SpriteBatch.<init>(SpriteBatch.java:142)
at com.badlogic.gdx.graphics.g2d.SpriteBatch.<init>(SpriteBatch.java:121)
at com.badlogic.gdx.graphics.g2d.SpriteBatch.<init>(SpriteBatch.java:115)

我的项目中添加了以下库:

I have the following libraries added to my project:

  • gdx.jar
  • gdx-sources.jar
  • gdx-natives.jar
  • gdx-backend-lwjgl.jar
  • gdx-backend-lwjgl-natives.jar

我错过了什么吗?

我搜索了高低,但我找到的所有内容都是针对 Android 的,并告诉我将 arm 文件夹中的 .so 库添加到我的项目中,但这对我来说对于 wintel 平台上的桌面项目没有意义.

I have searched high and low, but everything I find is for Android and tells me to add the .so libs from the arm folders to my project, but that doesn't make sense to me for a desktop project on wintel platform.

推荐答案

我建议你使用 这个 GUI.它应该为您提供适用于所有平台的有效设置.您也可以使用最新的夜间版本并检查问题是否仍然存在.问题可能是本机库与其他 jar 不匹配.

I'd advise you to setup your projects with this GUI. It should provide you with a valid setup for all platforms. You may also use the latest nightly builds and check if the problem still occurs. The problem might be that the native libraries do not match the other jars.

另一个问题可能是您过早地实例化 SpriteBatch(或其他内部使用 SpriteBatch 的东西)(在堆栈跟踪中看起来有点像这样).例如像这样静态地:

Another problem might be that you instantiate a SpriteBatch (or something else which internally uses a SpriteBatch) too early (looked a bit like this in the stacktrace). For example statically like this:

private static SpriteBatch batch = new SpriteBatch();

这不起作用,因为此时未正确设置 libgdx.相反,请在游戏的 create/show 方法中创建此类内容.

This won't work, since libgdx wasn't setup correctly at this point in time. Instead, create such things in the create/show methods of your game.

相关文章