2013-08-28 94 views
2

我使用的EXACT代碼與this教程中使用的代碼相同,但由於某些原因,我在嘗試運行該項目時遇到錯誤。 LibGDX的默認項目工作正常。LibGDX/Box2D UnsatisfiedLinkError

錯誤:

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() { 
    } 

} 

回答

5

你可能想嘗試GdxNativesLoader.load();。以靜態的方式執行,即當JVM加載類時:即,當JVM加載類時:當代碼或java庫調用某些本地代碼時,顯然鏈接錯誤發生。

+0

你在哪裏建議我放那條線?代碼在它到達'create()'方法之前就會中斷 – Chris

+0

瞭解它,謝謝!我會在問題中發佈修復,但我會upvote並接受你的答案,再次感謝 – Chris

+0

我已經更新了我的答案 – aquaraga