0

I keep getting errors with andengine. Here is log. Below is the code from the tutorial that gives me errors.

E/AndEngine(28075): BaseActivity.onCreateScene failed. @(Thread: 'GLThread 1450')
E/AndEngine(28075): java.lang.NullPointerException
E/AndEngine(28075):     at com.tegracode.prvaigra.BaseActivity.onCreateScene(BaseActivity.java:61)
E/AndEngine(28075):     at org.andengine.ui.activity.SimpleBaseGameActivity.onCreateScene(SimpleBaseGameActivity.java:48)
E/AndEngine(28075):     at org.andengine.ui.activity.BaseGameActivity$3.onCreateResourcesFinished(BaseGameActivity.java:169)
E/AndEngine(28075):     at org.andengine.ui.activity.SimpleBaseGameActivity.onCreateResources(SimpleBaseGameActivity.java:43)
E/AndEngine(28075):     at org.andengine.ui.activity.BaseGameActivity.onCreateGame(BaseGameActivity.java:181)
E/AndEngine(28075):     at org.andengine.ui.activity.BaseGameActivity.onSurfaceCreated(BaseGameActivity.java:110)
E/AndEngine(28075):     at org.andengine.opengl.view.EngineRenderer.onSurfaceCreated(EngineRenderer.java:80)
E/AndEngine(28075):     at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1446)
E/AndEngine(28075):     at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1216)
D/AndEngine(28075): BaseActivity.onSurfaceChanged(Width=800,  Height=480) @(Thread: 'GLThread 1450')

Here is the Code:

public class BaseActivity extends SimpleBaseGameActivity  {
    static final int CAMERA_WIDTH = 800;
    static final int CAMERA_HEIGHT = 480;
    public Font mFont;
    public Camera mCamera;
    public Scene mCurrentScene;
    public static BaseActivity instance;

    public EngineOptions onCreateEngineOptions() {
        instance = this;
        mCamera = new Camera(0, 0, CAMERA_WIDTH, CAMERA_HEIGHT);

        return new EngineOptions(true, ScreenOrientation.LANDSCAPE_SENSOR, new RatioResolutionPolicy(CAMERA_WIDTH, CAMERA_HEIGHT), mCamera);
    }

    protected void onCreateResources() {
        mFont = FontFactory.create(this.getFontManager(),this.getTextureManager(), 256, 256,Typeface.create(Typeface.DEFAULT, Typeface.BOLD), 32);
        mFont.load();
    }

    protected Scene onCreateScene() {
        mEngine.registerUpdateHandler(new FPSLogger());

        this.mCurrentScene = new Scene();
        this.mCurrentScene.setBackground(new Background(3f, 6f, 2f));

        return this.mCurrentScene;
    }
}
4

1 回答 1

1

移动这一行:

this.mCurrentScene.setBackground(新背景(3f, 6f, 2f));

到 onPopulateScene 方法。那里的场景应该是非空的。

于 2012-07-24T19:28:47.443 回答