0
快速的问题: 我有这样的代码:AndEngine NullPointerException异常时声音
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;
}
而且
protected void onCreateResources() {
SoundFactory.setAssetBasePath("mfx/");
try {
this.testSound = SoundFactory.createSoundFromAsset(this.mEngine.getSoundManager(), this, "explosion.ogg");
} catch (final IOException e) {
Debug.e(e);
}
}
我finaly发挥它有这个活动作为一个领域的又一类:
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;
}
});
任何想法为什么我会得到一个空指针异常?
谢谢!