0

I got this error when creating the background in my game. But if I use the same code in another project, it works great. I can't understand. Here is my code:

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;
}

- And my 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)

Error at line this.bg_BTA = new BitmapTextureAtlas(mEngine.getTextureManager(),1024, 1024, TextureOptions.BILINEAR_PREMULTIPLYALPHA);

Thank for your help!

Phong Ho
  • 5
  • 4

0 Answers0