Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.3k views
in Technique[技术] by (71.8m points)

android - ExceptionInInitializerError Physics World

I searched in a number of forums and it seems to be a common question. However i couldnt find a solution. I didnt do anything crazy so it seems stange that this happens.

@Override
protected Scene onCreateScene() {
    Scene s = new Scene();
    PhysicsWorld mWorld=new PhysicsWorld(new Vector2(0, SensorManager.GRAVITY_EARTH),true);
    s.registerUpdateHandler(mWorld);
    final Sprite eliSprite = new Sprite(400, 240, james_walking[3], getVertexBufferObjectManager());
    eliSprite.setScale(0.5f);
    s.attachChild(eliSprite);
    s.setTouchAreaBindingOnActionDownEnabled(true);
    return s;
}

I dont have much more to say because i dont know much about Andengine so a dummies explanation would be apreciated. After adding what you said the error goes out, however the PhysicsWorld still doesnt work. THe logcat says

02-27 17:07:51.153    2590-2639/com.company.m.appname D/dalvikvm﹕ No JNI_OnLoad found in /data/data/com.company.m.appname/lib/libandenginephysicsbox2dextension.so 0x41cdce70, skipping init
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Probably native libraries (.so files from lib dir) is missing from your APK. Check your project settings / build configuration.

If you're using android studio, you have to modify the sourceSet of andEngine and andEnginePhysicsBox2DExtension in build.gradle.

You have a folder in that projects where there are so files, you need to include the native libraries from there.

Check my answer here: jniLibs are not extended in gradle

Update based on your comments:

Add this to andEngine, andEnginePhysicsBox2d and your game build.gradle:

sourceSets {
    main {
        jni.srcDirs = []
        jniLibs.srcDir 'libs'
    }
}

Also add this to the defaultConfig section, for andEngine:

ndk {
   moduleName "andEngine"
}

and for andEnginePhysicsBox2d:

ndk {
    moduleName "andEnginePhysicsBox2dExtension"
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...