简体   繁体   English

LibGDX / Box2D UnsatisfiedLinkError

[英]LibGDX/Box2D UnsatisfiedLinkError

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. LibGDX的默认项目运行良好。

Error: 错误:

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); 

Edit: 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.) 编辑:在进一步调试后,我注释掉了涉及world变量的所有内容,并且程序运行了(除了黑框以外,什么都没有出现,因为我注释掉了注释world定义行时出错的所有内容。)

Edit2: Full code that works.(There are different ways of using GdxNativesLoader.load(); but this is the way I decided to use, thanks to aquaraga) Edit2:可以正常工作的完整代码。(使用GdxNativesLoader.load();方式有多种GdxNativesLoader.load();不过这是我决定使用的方式,这要感谢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() {  
     }  

}

You may want to try GdxNativesLoader.load(); 您可能想尝试GdxNativesLoader.load(); . Do it in a static manner, ie when JVM loads the class: 以静态方式进行操作,即当JVM加载类时:

static {
    GdxNativesLoader.load();
}

Apparently, the link error happens when your code or java library invokes some native code. 显然,当您的代码或Java库调用某些本机代码时,就会发生链接错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM