【问题标题】:LibGDX/Box2D UnsatisfiedLinkErrorLibGDX/Box2D UnsatisfiedLinkError
【发布时间】:2013-08-28 18:36:40
【问题描述】:

我使用的代码与 this 教程中使用的代码完全相同,但由于某种原因,我在尝试运行项目时遇到错误。 LibGDX 的默认项目运行良好。

错误:

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)

它所指的行(类中的第一行):

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

编辑:在进一步调试后,我注释掉了涉及 world 变量的任何内容并且程序运行(除了黑框之外什么都没有显示,因为我在注释掉 world 定义行时注释掉了任何错误。 )

Edit2:完整代码有效。(有不同的使用方式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() {  
     }  

}

【问题讨论】:

    标签: java android box2d libgdx


    【解决方案1】:

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

    static {
        GdxNativesLoader.load();
    }
    

    显然,当您的代码或 java 库调用一些本机代码时,会发生链接错误。

    【讨论】:

    • 你建议我把那行放在哪里?代码在到达create() 方法之前就中断了
    • 知道了,谢谢!我将在问题中发布修复程序,但我会投票并接受您的回答,再次感谢
    • 在我看到更新之前,我已经用那条线修复了我的问题,不过谢谢
    • 回答已接受,谢谢。现在我可以尝试为我的课业应用发布为期 1 天的测试版
    • 那么我应该把这个放在哪里??
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-06-22
    • 2014-07-02
    • 2013-07-07
    • 2014-03-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多