【发布时间】:2020-07-25 22:16:54
【问题描述】:
i'm a beginner programmer and need some help. I'm using android studio and libgdx. I created a project. When I try to use box2d", I get this error:
“线程“LWJGL 应用程序”com.badlogic.gdx.utils.GdxRuntimeException 中的异常:java.lang.ExceptionInInitializerError”
Whenever I run a LibGDX project that uses box2d I always get a "java.lang.ExceptionInInitializerError" at the line where I initialize the world. I am just learning it in a tutorial series. I am trying to make am image into a physics body so it can fall. I think the problem may have something to do with the version of libGDX and android studio that I am using. Maybe both of them don't go too well. Please I would appreciate your help. Thank you.
public class MainGame extends ApplicationAdapter {
@Override
public void create() {
texture = new Texture("badlogic.jpg");
spriteBatch = new SpriteBatch();
sprite = new Sprite(texture);
world = new World(new Vector2(0, -98f),true);
body = createBody();
PolygonShape shape = new PolygonShape();
shape.setAsBox(sprite.getWidth()/2,sprite.getY()/2);
FixtureDef fixtureDef = new FixtureDef();
fixtureDef.density = 1f;
fixtureDef.shape = shape;
Fixture fixture = body.createFixture(fixtureDef);
shape.dispose();
}
}
我运行程序时logcat的错误如下所示
Exception in thread "LWJGL Application" com.badlogic.gdx.utils.GdxRuntimeException: java.lang.ExceptionInInitializerError
at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:135)
Caused by: java.lang.ExceptionInInitializerError
at com.ikedinachim.com.MainGame.create(MainGame.java:31)
at com.badlogic.gdx.backends.lwjgl.LwjglApplication.mainLoop(LwjglApplication.java:151)
at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:128)
Caused by: com.badlogic.gdx.utils.GdxRuntimeException: Couldn't load shared library 'gdx-box2d64.dll' for target: Windows 10, 64-bit
at com.badlogic.gdx.utils.SharedLibraryLoader.load(SharedLibraryLoader.java:125)
at com.badlogic.gdx.physics.box2d.World.<clinit>(World.java:187)
... 3 more
Caused by: com.badlogic.gdx.utils.GdxRuntimeException: Unable to read file for extraction: gdx-box2d64.dll
at com.badlogic.gdx.utils.SharedLibraryLoader.readFile(SharedLibraryLoader.java:133)
at com.badlogic.gdx.utils.SharedLibraryLoader.loadFile(SharedLibraryLoader.java:289)
at com.badlogic.gdx.utils.SharedLibraryLoader.load(SharedLibraryLoader.java:121)
... 4 more
【问题讨论】:
标签: java libgdx box2d game-physics game-development