LibGDX/Box2D UnsatisfiedLinkError [英] LibGDX/Box2D UnsatisfiedLinkError

查看:121
本文介绍了LibGDX/Box2D UnsatisfiedLinkError的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用与教程,但由于某些原因,在尝试运行该项目时出现错误. LibGDX的默认项目运行良好.

I'm using the EXACT same code as used in this tutorial but for some reason I get an error while trying to run the project. The default project for LibGDX worked fine.

错误:

Exception in thread "main" java.lang.UnsatisfiedLinkError: com.badlogic.gdx.physics.box2d.World.newWorld(FFZ)J
at com.badlogic.gdx.physics.box2d.World.newWorld(Native Method)
at com.badlogic.gdx.physics.box2d.World.<init>(World.java:222)
at net.ocps.tchs.permarun.PermaRun.<init>(PermaRun.java:19)
at net.ocps.tchs.permarun.Main.main(Main.java:14)

它所引用的行(类的第一行):

Line it is referring to(the first line in the class):

World world = new World(new Vector2(0, -100), true); 

在进一步调试后,我注释掉了涉及world变量的所有内容,并且程序运行了(除了黑框之外,什么都没有出现,因为我注释掉了注释world定义行时出错的所有内容. )

Upon further debugging, I commented out anything involving the the world variable and the program ran (nothing showed up except a black box though because I commented out anything that errors upon commenting out the world definition line.)

Edit2:可以正常工作的完整代码.(使用GdxNativesLoader.load();的方式不同,但是由于aquaraga的缘故,这是我决定使用的方式)

Full code that works.(There are different ways of using GdxNativesLoader.load(); but this is the way I decided to use, thanks to aquaraga)

import com.badlogic.gdx.ApplicationListener;  
import com.badlogic.gdx.Gdx;  
import com.badlogic.gdx.graphics.GL10;  
import com.badlogic.gdx.graphics.OrthographicCamera;  
import com.badlogic.gdx.math.Vector2;  
import com.badlogic.gdx.physics.box2d.Body;  
import com.badlogic.gdx.physics.box2d.BodyDef;  
import com.badlogic.gdx.physics.box2d.BodyDef.BodyType;  
import com.badlogic.gdx.physics.box2d.Box2DDebugRenderer;  
import com.badlogic.gdx.physics.box2d.CircleShape;  
import com.badlogic.gdx.physics.box2d.FixtureDef;  
import com.badlogic.gdx.physics.box2d.PolygonShape;  
import com.badlogic.gdx.physics.box2d.World;  
import com.badlogic.gdx.utils.GdxNativesLoader;
public class PermaRun implements ApplicationListener {  
     World world;  
     Box2DDebugRenderer debugRenderer;  
     OrthographicCamera camera;  
     static final float BOX_STEP=1/60f;  
     static final int BOX_VELOCITY_ITERATIONS=6;  
     static final int BOX_POSITION_ITERATIONS=2;  
     static final float WORLD_TO_BOX=0.01f;  
     static final float BOX_WORLD_TO=100f;  
     @Override  
     public void create() {
          GdxNativesLoader.load();
          world = new World(new Vector2(0.0f, -100.0f), true);
          camera = new OrthographicCamera();  
          camera.viewportHeight = 320;  
          camera.viewportWidth = 480;  
          camera.position.set(camera.viewportWidth * .5f, camera.viewportHeight * .5f, 0f);  
          camera.update();  
          //Ground body  
          BodyDef groundBodyDef =new BodyDef();  
          groundBodyDef.position.set(new Vector2(0, 10));  
          Body groundBody = world.createBody(groundBodyDef);  
          PolygonShape groundBox = new PolygonShape();  
          groundBox.setAsBox((camera.viewportWidth) * 2, 10.0f);  
          groundBody.createFixture(groundBox, 0.0f);  
          //Dynamic Body  
          BodyDef bodyDef = new BodyDef();  
          bodyDef.type = BodyType.DynamicBody;  
          bodyDef.position.set(camera.viewportWidth / 2, camera.viewportHeight / 2);  
          Body body = world.createBody(bodyDef);  
          CircleShape dynamicCircle = new CircleShape();  
          dynamicCircle.setRadius(5f);  
          FixtureDef fixtureDef = new FixtureDef();  
          fixtureDef.shape = dynamicCircle;  
          fixtureDef.density = 1.0f;  
          fixtureDef.friction = 0.0f;  
          fixtureDef.restitution = 1;  
          body.createFixture(fixtureDef);  
          debugRenderer = new Box2DDebugRenderer();  
     }  
     @Override  
     public void dispose() {  
     }  
     @Override  
     public void render() {            
          Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);  
          debugRenderer.render(world, camera.combined);  
          world.step(BOX_STEP, BOX_VELOCITY_ITERATIONS, BOX_POSITION_ITERATIONS);  
     }  
     @Override  
     public void resize(int width, int height) {  
     }  
     @Override  
     public void pause() {  
     }  
     @Override  
     public void resume() {  
     }  

}

推荐答案

您可能想尝试GdxNativesLoader.load();.以静态方式进行操作,即当JVM加载类时:

You may want to try GdxNativesLoader.load();. Do it in a static manner, i.e. when JVM loads the class:

static {
    GdxNativesLoader.load();
}

显然,当您的代码或Java库调用某些本机代码时,就会发生链接错误.

Apparently, the link error happens when your code or java library invokes some native code.

这篇关于LibGDX/Box2D UnsatisfiedLinkError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆