我目前正在尝试将一些物理实现到我的应用中,但是在编译时我遇到了问题。
编译错误:
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)
我的代码:
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);
}
}
基本上我正在尝试制作可以移动的2D图形。我对Jbox2d很陌生,所以如果有人有更容易使用的物理引擎,我也会接受建议!
我将jbox2d-library-2.1.2.2.jar文件放在名为&#39; libs&#39;的文件夹中。我已将以下内容添加到app build.gradle
中 dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile files('libs/jbox2d-library-2.1.2.2.jar')
}
答案 0 :(得分:0)
我不了解jbox2d,但是发生的事情是sl4j(这是一个日志记录 facade )无法找到记录实现。
您可能需要做的就是在类路径中提供一个,例如: log4j的
compile 'org.slf4j:slf4j-log4j12:1.6.4'
(不确定确切的版本)
BTW,jbox2d在其documentation(&#34;没有使用maven&#34; 构建)中提到了这一点:)
编辑:您没有从maven repo获取依赖关系的任何原因?似乎更容易从here获取它并让gradle处理依赖...
'org.jbox2d:jbox2d:2.1.2.2'