UnsatisfiedLinkError Libgdx桌面

jon*_*zza 5 java java-native-interface libgdx unsatisfiedlinkerror

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

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)
Run Code Online (Sandbox Code Playgroud)

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

  • gdx.jar
  • GDX-sources.jar
  • GDX-natives.jar
  • GDX-后端,lwjgl.jar
  • GDX-后端-LWJGL-natives.jar

我错过了什么吗?

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

noo*_*one 20

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

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

private static SpriteBatch batch = new SpriteBatch();
Run Code Online (Sandbox Code Playgroud)

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

  • 我很确定它是第二个答案(在Libgdx初始化之前调用SpriteBatch构造函数). (10认同)