我一直在使用andengine获得错误。 这是日志。以下是教程中给我错误的代码。
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')
以下是代码:
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;
}
}
答案 0 :(得分:1)
移动此行:
this.mCurrentScene.setBackground(new Background(3f,6f,2f));
到onPopulateScene方法。那里的场景应该是非空的。