[英]Android Studio Jbox2D java.lang.NoClassDefFoundError: org.slf4j.LoggerFactory
I'm currently trying to implement some physics into my app, however I am running into a problem when compiling. 我目前正在尝试在我的应用程序中实现一些物理功能,但是编译时遇到了问题。
Compilation error: 编译错误:
01-18 18:38:49.165 32473-32473/com.example.anthonys.pennyhockey E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.example.anthonys.pennyhockey, PID: 32473
java.lang.NoClassDefFoundError: org.slf4j.LoggerFactory
at org.jbox2d.pooling.normal.MutableStack.<clinit>(MutableStack.java:35)
at org.jbox2d.pooling.normal.DefaultWorldPool.<init>(DefaultWorldPool.java:66)
at org.jbox2d.dynamics.World.<init>(World.java:122)
at com.example.anthonys.pennyhockey.Play.<init>(Play.java:52)
at java.lang.Class.newInstanceImpl(Native Method)
at java.lang.Class.newInstance(Class.java:1208)
at android.app.Instrumentation.newActivity(Instrumentation.java:1061)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2122)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2271)
at android.app.ActivityThread.access$800(ActivityThread.java:144)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1205)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5146)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:796)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:612)
at dalvik.system.NativeStart.main(Native Method)
my code: 我的代码:
package com.example.anthonys.pennyhockey;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import org.jbox2d.collision.shapes.PolygonShape;
import org.jbox2d.common.Vec2;
import org.jbox2d.dynamics.Body;
import org.jbox2d.dynamics.BodyDef;
import org.jbox2d.dynamics.BodyType;
import org.jbox2d.dynamics.FixtureDef;
import org.jbox2d.dynamics.World;
public class Play extends Activity {
private void definition()
{
BodyDef penny = new BodyDef();
penny.type = BodyType.DYNAMIC;
penny.position.set(0,20);
penny.angle = 0;
Body myObject = world.createBody(penny);
PolygonShape pennyShape = new PolygonShape();
pennyShape.setAsBox(0.75f,0.75f);
FixtureDef pennyFixture = new FixtureDef();
pennyFixture.shape = pennyShape;
pennyFixture.density = 1;
myObject.createFixture(pennyFixture);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_play);
}
World world = new World(new Vec2(0, -9.8f), false);
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.play, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
} }
Basically I am trying to make a 2D figure that can be moved around. 基本上,我正在尝试制作可以移动的2D图形。 I'm quite new to Jbox2d so if anyone has any easier physics engines I could use, I would also be open to suggestion!
我对Jbox2d还是很陌生,所以如果有人可以使用任何更简单的物理引擎,我也欢迎您提出建议!
I have the jbox2d-library-2.1.2.2.jar file in a folder named 'libs'. 我在名为“ libs”的文件夹中有jbox2d-library-2.1.2.2.jar文件。 I have added the following to the app build.gradle
我已将以下内容添加到应用程序build.gradle中
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile files('libs/jbox2d-library-2.1.2.2.jar')
}
I don't know about jbox2d, but what happened is that sl4j (which is a logging facade ) could not find a logging implementation . 我不了解jbox2d,但是发生的是sl4j(这是一个日志记录外观 )找不到日志记录实现 。
Probably all you need to do is providing one in you classpath, eg log4j 您可能需要做的就是在类路径中提供一个,例如log4j
compile 'org.slf4j:slf4j-log4j12:1.6.4'
(not sure about the exact version though) (虽然不确定确切的版本)
BTW, jbox2d mentions this in its documentation ( "not building with maven" ) :) 顺便说一句,jbox2d在其文档中提到了这一点( “不使用maven进行构建” ):)
EDIT : any reason you don't get the dependencies from a maven repo? 编辑 :任何原因您没有从Maven存储库中获取依赖项? Seems much easier to just get it from here and let gradle take care of the dependencies...
似乎更容易从这里获取它,并让gradle处理依赖项...
'org.jbox2d:jbox2d:2.1.2.2'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.