Quick question:
I’ve got this code:
public EngineOptions onCreateEngineOptions() {
instance = this;
mCamera = new org.andengine.engine.camera.Camera(0, 0, CAMERA_WIDTH, CAMERA_HEIGHT);
EngineOptions engineOptions = new EngineOptions(true, ScreenOrientation.LANDSCAPE_SENSOR, new RatioResolutionPolicy(CAMERA_WIDTH, CAMERA_HEIGHT), mCamera);
engineOptions.getAudioOptions().setNeedsSound(true);
//engineOptions.getAudioOptions().setNeedsMusic(true);
return engineOptions;
}
And
protected void onCreateResources() {
SoundFactory.setAssetBasePath("mfx/");
try {
this.testSound = SoundFactory.createSoundFromAsset(this.mEngine.getSoundManager(), this, "explosion.ogg");
} catch (final IOException e) {
Debug.e(e);
}
}
And I finaly play it on another class that has this activity as a field :
activity.mCurrentScene.registerTouchArea(image);
activity.mCurrentScene.setOnAreaTouchListener(new IOnAreaTouchListener() {
@Override
public boolean onAreaTouched(TouchEvent pSceneTouchEvent,
ITouchArea pTouchArea, float pTouchAreaLocalX,
float pTouchAreaLocalY) {
Zancudo.this.activity.testSound.play();
return false;
}
});
Any ideas why am I getting a nullpointer exception ?
Thank you!
For play sound you are using like below
This looks like the issue because here the activity object is not instantiated in the
Zancudoclass.To access the testSound you need to get the instance of the Zancudo activity.