Search code examples
javalibgdx

UnsatisfiedLinkError when calling new World()


My error:

Exception in thread "LWJGL Application" com.badlogic.gdx.utils.GdxRuntimeException: java.lang.UnsatisfiedLinkError: org.jbox2d.common.Timer.now()D
    at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:130)
Caused by: java.lang.UnsatisfiedLinkError: org.jbox2d.common.Timer.now()D
    at org.jbox2d.common.Timer.now(Native Method)
    at org.jbox2d.common.Timer.reset(Timer.java:35)
    at org.jbox2d.common.Timer.<init>(Timer.java:31)
    at org.jbox2d.dynamics.World.<init>(World.java:587)
    at org.jbox2d.dynamics.World.<init>(World.java:158)
    at org.jbox2d.dynamics.World.<init>(World.java:154)
    at org.jbox2d.dynamics.World.<init>(World.java:145)
    at com.badlogic.gdx.physics.box2d.World.<init>(World.java:61)
    at com.example.blockbunny.states.Play.<init>(Play.java:22)
    at com.example.blockbunny.handlers.GameStateManager.getState(GameStateManager.java:36)
    at com.example.blockbunny.handlers.GameStateManager.pushState(GameStateManager.java:46)
    at com.example.blockbunny.handlers.GameStateManager.<init>(GameStateManager.java:20)
    at com.example.blockbunny.main.Game.create(Game.java:33)
    at com.badlogic.gdx.backends.lwjgl.LwjglApplication.mainLoop(LwjglApplication.java:146)
    at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:123)

And this occurs when I do this:

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

I have looked online, and some solutions included using this:

import com.badlogic.gdx.utils.GdxNativesLoader;
GdxNativesLoader.load();

However, I don't know where to put this function, and if it even works (I tried putting it in several different places)

How can I fix this issue?

Help will be appreciated, thanks!

As requested, here are my imports:

import static com.example.blockbunny.handlers.B2DVars.PPM;

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.FixtureDef;
import com.badlogic.gdx.physics.box2d.PolygonShape;
import com.badlogic.gdx.physics.box2d.World;
import com.example.blockbunny.handlers.GameStateManager;
import com.example.blockbunny.main.Game;

Solution

  • I used Box2d several time with libgdx and i never encountered such a problem :

    here what i propose t you :

    GdxNativesLoader.load(); should be put on the create() method, but that doesn't seem to work with you

    also try call it in a static way like this :

    static {
        GdxNativesLoader.load();
    }
    

    but i thin your problem is the extension of the library that you are using verify that you are using gdx-box2d and not gdx-box2d-gwt which is used only for Html project

    Verify that you are using the right (jar file) /(extension library) : gdx-box2d.jar and gdx-box2d-natives.jar (also verify the build path)

    also try :

    upgrade the box2d version that you're using

    those were all the arrows i had ! hope one of it will work

    Good luck !!