My code physicsremoveexample What’s wrong with Java (andengine)?
•
Java
Try to take an example from here. Physicsremoveexample java.
When the program starts, I receive this message:
Sorry! The application PhysicsRemoveExample(process org.anddev.andengine.PhysicsRemoveExample) has stopped unexpectedly. Please try again.
I have build path andengine Jar and andenginephysics@R_552_2419 @2dextension. jar assets / gfx – > face_@ R_ 552_ 2419@_tiled.png And face_ circle_ tiled. png.
This is me at physicsremoveexample Java code in Java Same as in the example, but I changed to extend basegameactivity
package org.anddev.andengine.PhysicsRemoveExample;
import org.anddev.andengine.engine.Engine;
import org.anddev.andengine.engine.camera.Camera;
import org.anddev.andengine.engine.options.EngineOptions;
import org.anddev.andengine.engine.options.EngineOptions.ScreenOrientation;
import org.anddev.andengine.engine.options.resolutionpolicy.RatioResolutionPolicy;
import org.anddev.andengine.entity.primitive.Rectangle;
import org.anddev.andengine.entity.scene.Scene;
import org.anddev.andengine.entity.scene.Scene.IOnAreaTouchListener;
import org.anddev.andengine.entity.scene.Scene.IOnSceneTouchListener;
import org.anddev.andengine.entity.scene.Scene.ITouchArea;
import org.anddev.andengine.entity.scene.background.ColorBackground;
import org.anddev.andengine.entity.shape.Shape;
import org.anddev.andengine.entity.sprite.AnimatedSprite;
import org.anddev.andengine.entity.util.FPSLogger;
import org.anddev.andengine.extension.physics.@R_552_2419@2d.PhysicsConnector;
import org.anddev.andengine.extension.physics.@R_552_2419@2d.PhysicsFactory;
import org.anddev.andengine.extension.physics.@R_552_2419@2d.PhysicsWorld;
import org.anddev.andengine.input.touch.TouchEvent;
import org.anddev.andengine.opengl.texture.Texture;
import org.anddev.andengine.opengl.texture.TextureOptions;
import org.anddev.andengine.opengl.texture.region.TextureRegionFactory;
import org.anddev.andengine.opengl.texture.region.TiledTextureRegion;
import org.anddev.andengine.sensor.accelerometer.AccelerometerData;
import org.anddev.andengine.sensor.accelerometer.IAccelerometerListener;
import org.anddev.andengine.ui.activity.BaseGameActivity;
import android.hardware.SensorManager;
import android.widget.Toast;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.physics.@R_552_2419@2d.Body;
import com.badlogic.gdx.physics.@R_552_2419@2d.FixtureDef;
import com.badlogic.gdx.physics.@R_552_2419@2d.BodyDef.BodyType;
/**
* @author Nicolas Gramlich
* @since 18:47:08 - 19.03.2010
*/
public class PhysicsRemoveExample extends BaseGameActivity implements IAccelerometerListener,IOnSceneTouchListener,IOnAreaTouchListener {
// ===========================================================
// Constants
// ===========================================================
private static final int CAMERA_WIDTH = 720;
private static final int CAMERA_HEIGHT = 480;
// ===========================================================
// Fields
// ===========================================================
private Texture mTexture;
private TiledTextureRegion m@R_552_2419@FaceTextureRegion;
private TiledTextureRegion mCircleFaceTextureRegion;
private PhysicsWorld mPhysicsWorld;
private int mFaceCount = 0;
private final Vector2 mTempVector = new Vector2();
// ===========================================================
// Constructors
// ===========================================================
// ===========================================================
// Getter & Setter
// ===========================================================
// ===========================================================
// Methods for/from SuperClass/Interfaces
// ===========================================================
@Override
public Engine onLoadEngine() {
Toast.makeText(this,"Touch the screen to add objects. Touch an object to remove it.",Toast.LENGTH_LONG).show();
final Camera camera = new Camera(0,CAMERA_WIDTH,CAMERA_HEIGHT);
final EngineOptions engineOptions = new EngineOptions(true,ScreenOrientation.LANDSCAPE,new RatioResolutionPolicy(CAMERA_WIDTH,CAMERA_HEIGHT),camera);
engineOptions.getTouchOptions().setRunOnUpdateThread(true);
return new Engine(engineOptions);
}
@Override
public void onLoadResources() {
this.mTexture = new Texture(64,64,TextureOptions.BILINEAR_PREMULTIPLYALPHA);
TextureRegionFactory.setAssetBasePath("gfx/");
this.m@R_552_2419@FaceTextureRegion = TextureRegionFactory.createTiledFromAsset(this.mTexture,this,"face_@R_552_2419@_tiled.png",2,1); // 64x32
this.mCircleFaceTextureRegion = TextureRegionFactory.createTiledFromAsset(this.mTexture,"face_circle_tiled.png",32,1); // 64x32
this.mEngine.getTextureManager().loadTexture(this.mTexture);
this.enableAccelerometerSensor(this);
}
@Override
public Scene onLoadScene() {
this.mEngine.registerUpdateHandler(new FPSLogger());
final Scene scene = new Scene(2);
scene.setBackground(new ColorBackground(0,0));
scene.setOnSceneTouchListener(this);
this.mPhysicsWorld = new PhysicsWorld(new Vector2(0,SensorManager.GRAVITY_EARTH),false);
final Shape ground = new Rectangle(0,CAMERA_HEIGHT - 2,2);
final Shape roof = new Rectangle(0,2);
final Shape left = new Rectangle(0,CAMERA_HEIGHT);
final Shape right = new Rectangle(CAMERA_WIDTH - 2,CAMERA_HEIGHT);
final FixtureDef wallFixtureDef = PhysicsFactory.createFixtureDef(0,0.5f,0.5f);
PhysicsFactory.create@R_552_2419@Body(this.mPhysicsWorld,ground,BodyType.StaticBody,wallFixtureDef);
PhysicsFactory.create@R_552_2419@Body(this.mPhysicsWorld,roof,left,right,wallFixtureDef);
scene.getBottomLayer().addEntity(ground);
scene.getBottomLayer().addEntity(roof);
scene.getBottomLayer().addEntity(left);
scene.getBottomLayer().addEntity(right);
scene.registerUpdateHandler(this.mPhysicsWorld);
scene.setOnAreaTouchListener(this);
return scene;
}
@Override
public boolean onAreaTouched(final TouchEvent pSceneTouchEvent,final ITouchArea pTouchArea,final float pTouchAreaLocalX,final float pTouchAreaLocalY) {
if(pSceneTouchEvent.getAction() == TouchEvent.ACTION_DOWN) {
PhysicsRemoveExample.this.removeFace((AnimatedSprite)pTouchArea);
return true;
}
return false;
}
public void onLoadComplete() {
}
@Override
public boolean onSceneTouchEvent(final Scene pScene,final TouchEvent pSceneTouchEvent) {
if(this.mPhysicsWorld != null) {
if(pSceneTouchEvent.getAction() == TouchEvent.ACTION_DOWN) {
this.addFace(pSceneTouchEvent.getX(),pSceneTouchEvent.getY());
return true;
}
}
return false;
}
@Override
public void onAccelerometerChanged(final AccelerometerData pAccelerometerData) {
this.mTempVector.set(pAccelerometerData.getY(),pAccelerometerData.getX());
this.mPhysicsWorld.setGravity(this.mTempVector);
}
// ===========================================================
// Methods
// ===========================================================
private void addFace(final float pX,final float pY) {
final Scene scene = this.mEngine.getScene();
this.mFaceCount++;
final AnimatedSprite face;
final Body body;
final FixtureDef objectFixtureDef = PhysicsFactory.createFixtureDef(1,0.5f);
if(this.mFaceCount % 2 == 0) {
face = new AnimatedSprite(pX,pY,this.m@R_552_2419@FaceTextureRegion);
body = PhysicsFactory.create@R_552_2419@Body(this.mPhysicsWorld,face,BodyType.DynamicBody,objectFixtureDef);
} else {
face = new AnimatedSprite(pX,this.mCircleFaceTextureRegion);
body = PhysicsFactory.createCircleBody(this.mPhysicsWorld,objectFixtureDef);
}
face.animate(200,true);
face.setUpdatePhysics(false);
scene.registerTouchArea(face);
scene.getTopLayer().addEntity(face);
this.mPhysicsWorld.registerPhysicsConnector(new PhysicsConnector(face,body,true,false,false));
}
private void removeFace(final AnimatedSprite face) {
final Scene scene = this.mEngine.getScene();
final PhysicsConnector facePhysicsConnector = this.mPhysicsWorld.getPhysicsConnectorManager().findPhysicsConnectorByShape(face);
this.mPhysicsWorld.unregisterPhysicsConnector(facePhysicsConnector);
this.mPhysicsWorld.destroyBody(facePhysicsConnector.getBody());
scene.unregisterTouchArea(face);
scene.getTopLayer().removeEntity(face);
}
// ===========================================================
// Inner and Anonymous Classes
// ===========================================================
}
I received this error in logcat:
11-12 20:31:39.482: ERROR/vold(27): Error opening switch name path '/sys/class/switch/test' (No such file or directory) 11-12 20:31:39.482: ERROR/vold(27): Error bootstrapping switch '/sys/class/switch/test' (No such file or directory) 11-12 20:31:39.482: ERROR/vold(27): Error opening switch name path '/sys/class/switch/test2' (No such file or directory) 11-12 20:31:39.482: ERROR/vold(27): Error bootstrapping switch '/sys/class/switch/test2' (No such file or directory) 11-12 20:31:55.381: ERROR/BatteryService(52): usbOnlinePath not found 11-12 20:31:55.381: ERROR/BatteryService(52): batteryVoltagePath not found 11-12 20:31:55.381: ERROR/BatteryService(52): batteryTemperaturePath not found 11-12 20:31:55.401: ERROR/SurfaceFlinger(52): Couldn't open /sys/power/wait_for_fb_sleep or /sys/power/wait_for_fb_wake 11-12 20:32:01.131: ERROR/EventHub(52): Could not get driver version for /dev/input/mouse0,Not a typewriter 11-12 20:32:01.131: ERROR/EventHub(52): Could not get driver version for /dev/input/mice,Not a typewriter 11-12 20:32:01.351: ERROR/System(52): Failure starting core service 11-12 20:32:01.351: ERROR/System(52): java.lang.SecurityException 11-12 20:32:01.351: ERROR/System(52): at android.os.BinderProxy.transact(Native Method) 11-12 20:32:01.351: ERROR/System(52): at android.os.ServiceManagerProxy.addService(ServiceManagerNative.java:146) 11-12 20:32:01.351: ERROR/System(52): at android.os.ServiceManager.addService(ServiceManager.java:72) 11-12 20:32:01.351: ERROR/System(52): at com.android.server.ServerThread.run(SystemServer.java:176) 11-12 20:32:01.361: ERROR/AndroidRuntime(52): Crash logging skipped,no checkin service 11-12 20:32:12.683: ERROR/ActivityThread(103): Failed to find provider info for android.server.checkin 11-12 20:32:15.853: ERROR/ActivityThread(103): Failed to find provider info for android.server.checkin 11-12 20:32:16.183: ERROR/ActivityThread(103): Failed to find provider info for android.server.checkin 11-12 20:32:17.303: ERROR/MediaPlayerService(31): Couldn't open fd for content://settings/system/notification_sound 11-12 20:32:17.313: ERROR/MediaPlayer(52): Unable to to create media player 11-12 20:32:23.833: ERROR/AndroidRuntime(135): ERROR: thread attach Failed 11-12 20:32:32.292: ERROR/AndroidRuntime(178): ERROR: thread attach Failed 11-12 20:32:59.373: ERROR/AndroidRuntime(225): Uncaught handler: thread main exiting due to uncaught exception 11-12 20:32:59.533: ERROR/AndroidRuntime(225): java.lang.ExceptionInInitializerError 11-12 20:32:59.533: ERROR/AndroidRuntime(225): at org.anddev.andengine.PhysicsRemoveExample.PhysicsRemoveExample.onLoadScene(PhysicsRemoveExample.java:125) 11-12 20:32:59.533: ERROR/AndroidRuntime(225): at org.anddev.andengine.ui.activity.BaseGameActivity.doResume(BaseGameActivity.java:159) 11-12 20:32:59.533: ERROR/AndroidRuntime(225): at org.anddev.andengine.ui.activity.BaseGameActivity.onWindowFocusChanged(BaseGameActivity.java:83) 11-12 20:32:59.533: ERROR/AndroidRuntime(225): at com.android.internal.policy.impl.PhoneWindow$DecorView.onWindowFocusChanged(PhoneWindow.java:1969) 11-12 20:32:59.533: ERROR/AndroidRuntime(225): at android.view.View.dispatchWindowFocusChanged(View.java:3731) 11-12 20:32:59.533: ERROR/AndroidRuntime(225): at android.view.ViewGroup.dispatchWindowFocusChanged(ViewGroup.java:657) 11-12 20:32:59.533: ERROR/AndroidRuntime(225): at android.view.ViewRoot.handleMessage(ViewRoot.java:1819) 11-12 20:32:59.533: ERROR/AndroidRuntime(225): at android.os.Handler.dispatchMessage(Handler.java:99) 11-12 20:32:59.533: ERROR/AndroidRuntime(225): at android.os.Looper.loop(Looper.java:123) 11-12 20:32:59.533: ERROR/AndroidRuntime(225): at android.app.ActivityThread.main(ActivityThread.java:4363) 11-12 20:32:59.533: ERROR/AndroidRuntime(225): at java.lang.reflect.Method.invokeNative(Native Method) 11-12 20:32:59.533: ERROR/AndroidRuntime(225): at java.lang.reflect.Method.invoke(Method.java:521) 11-12 20:32:59.533: ERROR/AndroidRuntime(225): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860) 11-12 20:32:59.533: ERROR/AndroidRuntime(225): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618) 11-12 20:32:59.533: ERROR/AndroidRuntime(225): at dalvik.system.NativeStart.main(Native Method) 11-12 20:32:59.533: ERROR/AndroidRuntime(225): Caused by: java.lang.UnsatisfiedLinkError: Library andenginephysics@R_552_2419@2dextension not found 11-12 20:32:59.533: ERROR/AndroidRuntime(225): at java.lang.Runtime.loadLibrary(Runtime.java:489) 11-12 20:32:59.533: ERROR/AndroidRuntime(225): at java.lang.System.loadLibrary(System.java:557) 11-12 20:32:59.533: ERROR/AndroidRuntime(225): at org.anddev.andengine.extension.physics.@R_552_2419@2d.PhysicsWorld.<clinit>(PhysicsWorld.java:30) 11-12 20:32:59.533: ERROR/AndroidRuntime(225): ... 15 more 11-12 20:32:59.603: ERROR/dalvikvm(225): Unable to open stack trace file '/data/anr/traces.txt': Permission denied
What's up? Tried emulators 1.6 and 2.1 and created a new AVD I can complete Getting Started tutorial (video – 5 minutes) without any problem
Solution
inspect libandenginephysics@R_552_2419 @2dextension. Is the so file in the LIBS / armeabi folder
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码
