Another force close error

  ... the MultiTouch Extension for AndEngine.

Another force close error

Postby Creampuff » Tue Mar 22, 2011 7:03 am

Hey everyone, I've just been trying to set up the AnalogOnscreenControlsExample in a standalone app and I can't figure out where a "stopped unexpectedly" error is coming from.

Both the andengine and multitouchextension libs are added to the build path, and the AndroidManifest has been edited to allow everything the example does...

Whats really throwing me off is I think the debugger is saying the error is in...
if(MultiTouch.isSupported(this))

As if it doesn't know what 'this' is... anyone know why this would be any different then in the example?

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. package org.anddev.andengine.finalFrontier;
  2.  
  3. import javax.microedition.khronos.opengles.GL10;
  4.  
  5. import org.anddev.andengine.engine.Engine;
  6. import org.anddev.andengine.engine.camera.Camera;
  7. import org.anddev.andengine.engine.camera.hud.controls.AnalogOnScreenControl;
  8. import org.anddev.andengine.engine.camera.hud.controls.AnalogOnScreenControl.IAnalogOnScreenControlListener;
  9. import org.anddev.andengine.engine.camera.hud.controls.BaseOnScreenControl;
  10. import org.anddev.andengine.engine.handler.physics.PhysicsHandler;
  11. import org.anddev.andengine.engine.options.EngineOptions;
  12. import org.anddev.andengine.engine.options.EngineOptions.ScreenOrientation;
  13. import org.anddev.andengine.engine.options.resolutionpolicy.RatioResolutionPolicy;
  14. import org.anddev.andengine.entity.scene.Scene;
  15. import org.anddev.andengine.entity.scene.background.ColorBackground;
  16. import org.anddev.andengine.entity.sprite.Sprite;
  17. import org.anddev.andengine.entity.util.FPSLogger;
  18. import org.anddev.andengine.extension.input.touch.controller.MultiTouch;
  19. import org.anddev.andengine.extension.input.touch.controller.MultiTouchController;
  20. import org.anddev.andengine.extension.input.touch.exception.MultiTouchException;
  21. import org.anddev.andengine.opengl.texture.Texture;
  22. import org.anddev.andengine.opengl.texture.TextureOptions;
  23. import org.anddev.andengine.opengl.texture.region.TextureRegion;
  24. import org.anddev.andengine.opengl.texture.region.TextureRegionFactory;
  25. import org.anddev.andengine.ui.activity.BaseGameActivity;
  26. import org.anddev.andengine.util.MathUtils;
  27.  
  28. import android.widget.Toast;
  29.  
  30.  
  31. public class finalFrontier extends BaseGameActivity {
  32.         // ===========================================================
  33.         // Constants
  34.         // ===========================================================
  35.  
  36.         private static final int CAMERA_WIDTH = 480;
  37.         private static final int CAMERA_HEIGHT = 320;
  38.  
  39.         // ===========================================================
  40.         // Fields
  41.         // ===========================================================
  42.  
  43.         private Camera mCamera;
  44.  
  45.         private Texture mTexture;
  46.         private TextureRegion mFaceTextureRegion;
  47.  
  48.         private Texture mOnScreenControlTexture;
  49.         private TextureRegion mOnScreenControlBaseTextureRegion;
  50.         private TextureRegion mOnScreenControlKnobTextureRegion;
  51.  
  52.         private boolean mPlaceOnScreenControlsAtDifferentVerticalLocations = false;
  53.  
  54.         // ===========================================================
  55.         // Constructors
  56.         // ===========================================================
  57.  
  58.         // ===========================================================
  59.         // Getter & Setter
  60.         // ===========================================================
  61.  
  62.         // ===========================================================
  63.         // Methods for/from SuperClass/Interfaces
  64.         // ===========================================================
  65.  
  66.         @Override
  67.         public Engine onLoadEngine() {
  68.                 this.mCamera = new Camera(0, 0, CAMERA_WIDTH, CAMERA_HEIGHT);
  69.                 final Engine engine = new Engine(new EngineOptions(true, ScreenOrientation.LANDSCAPE, new RatioResolutionPolicy(CAMERA_WIDTH, CAMERA_HEIGHT), this.mCamera));
  70.  
  71.                 try {
  72.                         if(MultiTouch.isSupported(this)) {
  73.                                 engine.setTouchController(new MultiTouchController());
  74.                                 if(MultiTouch.isSupportedDistinct(this)) {
  75.                                         Toast.makeText(this, "MultiTouch detected --> Both controls will work properly!", Toast.LENGTH_LONG).show();
  76.                                 } else {
  77.                                         this.mPlaceOnScreenControlsAtDifferentVerticalLocations = true;
  78.                                         Toast.makeText(this, "MultiTouch detected, but your device has problems distinguishing between fingers.\n\nControls are placed at different vertical locations.", Toast.LENGTH_LONG).show();
  79.                                 }
  80.                         } else {
  81.                                 Toast.makeText(this, "Sorry your device does NOT support MultiTouch!\n\n(Falling back to SingleTouch.)\n\nControls are placed at different vertical locations.", Toast.LENGTH_LONG).show();
  82.                         }
  83.                 } catch (final MultiTouchException e) {
  84.                         Toast.makeText(this, "Sorry your Android Version does NOT support MultiTouch!\n\n(Falling back to SingleTouch.)\n\nControls are placed at different vertical locations.", Toast.LENGTH_LONG).show();
  85.                 }
  86.  
  87.                 return engine;
  88.         }
  89.  
  90.         @Override
  91.         public void onLoadResources() {
  92.                 TextureRegionFactory.setAssetBasePath("gfx/");
  93.  
  94.                 this.mTexture = new Texture(32, 32, TextureOptions.BILINEAR_PREMULTIPLYALPHA);
  95.                 this.mFaceTextureRegion = TextureRegionFactory.createFromAsset(this.mTexture, this, "face_box.png", 0, 0);
  96.  
  97.                 this.mOnScreenControlTexture = new Texture(256, 128, TextureOptions.BILINEAR_PREMULTIPLYALPHA);
  98.                 this.mOnScreenControlBaseTextureRegion = TextureRegionFactory.createFromAsset(this.mOnScreenControlTexture, this, "onscreen_control_base.png", 0, 0);
  99.                 this.mOnScreenControlKnobTextureRegion = TextureRegionFactory.createFromAsset(this.mOnScreenControlTexture, this, "onscreen_control_knob.png", 128, 0);
  100.  
  101.                 this.mEngine.getTextureManager().loadTextures(this.mTexture, this.mOnScreenControlTexture);
  102.         }
  103.  
  104.         @Override
  105.         public Scene onLoadScene() {
  106.                 this.mEngine.registerUpdateHandler(new FPSLogger());
  107.  
  108.                 final Scene scene = new Scene(1);
  109.                 scene.setBackground(new ColorBackground(0.09804f, 0.6274f, 0.8784f));
  110.  
  111.                 final int centerX = (CAMERA_WIDTH - this.mFaceTextureRegion.getWidth()) / 2;
  112.                 final int centerY = (CAMERA_HEIGHT - this.mFaceTextureRegion.getHeight()) / 2;
  113.                 final Sprite face = new Sprite(centerX, centerY, this.mFaceTextureRegion);
  114.                 final PhysicsHandler physicsHandler = new PhysicsHandler(face);
  115.                 face.registerUpdateHandler(physicsHandler);
  116.  
  117.                 scene.getLastChild().attachChild(face);
  118.  
  119.                 /* Velocity control (left). */
  120.                 final int x1 = 0;
  121.                 final int y1 = CAMERA_HEIGHT - this.mOnScreenControlBaseTextureRegion.getHeight();
  122.                 final AnalogOnScreenControl velocityOnScreenControl = new AnalogOnScreenControl(x1, y1, this.mCamera, this.mOnScreenControlBaseTextureRegion, this.mOnScreenControlKnobTextureRegion, 0.1f, new IAnalogOnScreenControlListener() {
  123.                         @Override
  124.                         public void onControlChange(final BaseOnScreenControl pBaseOnScreenControl, final float pValueX, final float pValueY) {
  125.                                 physicsHandler.setVelocity(pValueX * 100, pValueY * 100);
  126.                         }
  127.  
  128.                         @Override
  129.                         public void onControlClick(final AnalogOnScreenControl pAnalogOnScreenControl) {
  130.                                 /* Nothing. */
  131.                         }
  132.                 });
  133.                 velocityOnScreenControl.getControlBase().setBlendFunction(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA);
  134.                 velocityOnScreenControl.getControlBase().setAlpha(0.5f);
  135.  
  136.                 scene.setChildScene(velocityOnScreenControl);
  137.  
  138.  
  139.                 /* Rotation control (right). */
  140.                 final int y2 = (this.mPlaceOnScreenControlsAtDifferentVerticalLocations) ? 0 : y1;
  141.                 final int x2 = CAMERA_WIDTH - this.mOnScreenControlBaseTextureRegion.getWidth();
  142.                 final AnalogOnScreenControl rotationOnScreenControl = new AnalogOnScreenControl(x2, y2, this.mCamera, this.mOnScreenControlBaseTextureRegion, this.mOnScreenControlKnobTextureRegion, 0.1f, new IAnalogOnScreenControlListener() {
  143.                         @Override
  144.                         public void onControlChange(final BaseOnScreenControl pBaseOnScreenControl, final float pValueX, final float pValueY) {
  145.                                 if(pValueX == x1 && pValueY == x1) {
  146.                                         /*face.setRotation(x1); */
  147.                                 }
  148.                                 else {
  149.                                         face.setRotation(MathUtils.radToDeg((float)Math.atan2(pValueX, -pValueY)));
  150.                                 }
  151.                         }
  152.  
  153.                         @Override
  154.                         public void onControlClick(final AnalogOnScreenControl pAnalogOnScreenControl) {
  155.                                 /* Nothing. */
  156.                         }
  157.                 });
  158.                 rotationOnScreenControl.getControlBase().setBlendFunction(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA);
  159.                 rotationOnScreenControl.getControlBase().setAlpha(0.5f);
  160.  
  161.                 velocityOnScreenControl.setChildScene(rotationOnScreenControl);
  162.  
  163.                 return scene;
  164.         }
  165.  
  166.         @Override
  167.         public void onLoadComplete() {
  168.  
  169.         }
  170.  
  171.         // ===========================================================
  172.         // Methods
  173.         // ===========================================================
  174.  
  175.         // ===========================================================
  176.         // Inner and Anonymous Classes
  177.         // ===========================================================
  178. }
Parsed in 0.057 seconds, using GeSHi 1.0.8.4


Thanks in advance for all the help!
Creampuff
 
Posts: 4
Joined: Sun Mar 06, 2011 7:18 pm

Re: Another force close error

Postby Creampuff » Thu Mar 24, 2011 11:43 pm

SOLVED: I was apparently using an old version of the andengine.jar file. The systemsutil.class file was missing the hasSystemFeature method and this threw everything off.
Creampuff
 
Posts: 4
Joined: Sun Mar 06, 2011 7:18 pm


Return to MultiTouch

Who is online

Users browsing this forum: Google [Bot] and 1 guest