AndEngine:onCreateResources()中的java.lang.NullPointerException

时间:2014-05-17 15:44:33

标签: android nullpointerexception andengine

我在游戏中创建背景时遇到此错误。但是,如果我在另一个项目中使用相同的代码,它的效果很好。我无法理解。这是我的代码:

public class Play extends SimpleBaseGameActivity {

BitmapTextureAtlas bg_BTA;
TextureRegion bg_TR;

@Override
public EngineOptions onCreateEngineOptions() {
    this.mCamera = new Camera(0, 0, Config.SCREENWIDTH, Config.SCREENHIEGHT);
    EngineOptions option = new EngineOptions(true,
            Config.ScreenOrientation_Default, new RatioResolutionPolicy(
                    Config.SCREENWIDTH, Config.SCREENHIEGHT), this.mCamera);
    option.getAudioOptions().setNeedsMusic(true);
    option.getAudioOptions().setNeedsSound(true);
    return option;
}

@Override
protected void onCreateResources() {
    // TODO Auto-generated method stub
    this.bg_BTA = new BitmapTextureAtlas(mEngine.getTextureManager(),1024, 1024, TextureOptions.BILINEAR_PREMULTIPLYALPHA);
    this.bg_TR = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.bg_BTA, this.getAssets(), "bg/bg/bg0.png", 0, 0);
    this.bg_BTA.load();
}

@Override
protected Scene onCreateScene() {
    // TODO Auto-generated method stub
    mScene = new Scene();
    mScene.setTouchAreaBindingOnActionDownEnabled(true);
    mScene.setTouchAreaBindingOnActionMoveEnabled(true);

    Sprite mBackground = new Sprite(0, 0,
            Config.SCREENWIDTH, Config.SCREENHIEGHT, this.bg_TR, mEngine.getVertexBufferObjectManager());
    this.mScene.attachChild(mBackground);
    return mScene;
}

- 我的logcat:

05-17 22:12:13.521: E/AndEngine(1432): Play.onCreateGame failed. @(Thread: 'GLThread 136')
05-17 22:12:13.521: E/AndEngine(1432): java.lang.NullPointerException
05-17 22:12:13.521: E/AndEngine(1432):  at com.binnana.taptaplinklink.Play.onCreateResources(Play.java:153)
05-17 22:12:13.521: E/AndEngine(1432):  at org.andengine.ui.activity.SimpleBaseGameActivity.onCreateResources(SimpleBaseGameActivity.java:41)
05-17 22:12:13.521: E/AndEngine(1432):  at org.andengine.ui.activity.BaseGameActivity.onCreateGame(BaseGameActivity.java:181)
05-17 22:12:13.521: E/AndEngine(1432):  at org.andengine.ui.activity.BaseGameActivity.onSurfaceCreated(BaseGameActivity.java:110)
05-17 22:12:13.521: E/AndEngine(1432):  at org.andengine.opengl.view.EngineRenderer.onSurfaceCreated(EngineRenderer.java:80)
05-17 22:12:13.521: E/AndEngine(1432):  at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1494)
05-17 22:12:13.521: E/AndEngine(1432):  at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1240)

此行的错误.bg_BTA = new BitmapTextureAtlas(mEngine.getTextureManager(),1024,1024,TextureOptions.BILINEAR_PREMULTIPLYALPHA);

感谢您的帮助!

0 个答案:

没有答案