AndEngine的NullPointerException

时间:2015-01-16 02:46:42

标签: android nullpointerexception andengine

我根据this tutorial添加并引导到Android工作室。

但是,当简单地创建从SimpleBaseGameActivity扩展的GameActivity时,我收到此错误:

这是我的GameActivity代码:

public class GameActivity extends SimpleBaseGameActivity {
    @Override
    public EngineOptions onCreateEngineOptions() {
        return null;
    }
    @Override
    protected void onCreateResources() throws IOException {

    }

    @Override
    protected Scene onCreateScene() {
        return null;
    }
}

我的清单代码:

 <activity
     android:name="com.waylonhuang.game.MainActivity"
     android:label="@string/app_name" >
     <intent-filter>
         <action android:name="android.intent.action.MAIN" />

         <category android:name="android.intent.category.LAUNCHER" />
     </intent-filter>
</activity>
<activity
    android:name=".GameActivity"
    android:label="@string/app_name" >
</activity>

所以这就是错误:我错过了什么?

547-547/com.waylonhuang.game E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.waylonhuang.game, PID: 547
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.waylonhuang.game/com.waylonhuang.game.GameActivity}: java.lang.NullPointerException
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2198)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2257)
        at android.app.ActivityThread.access$800(ActivityThread.java:139)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1210)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:136)
        at android.app.ActivityThread.main(ActivityThread.java:5086)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:515)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
        at dalvik.system.NativeStart.main(Native Method)
 Caused by: java.lang.NullPointerException
        at org.andengine.engine.Engine.<init>(Engine.java:145)
        at org.andengine.ui.activity.BaseGameActivity.onCreateEngine(BaseGameActivity.java:92)
        at org.andengine.ui.activity.BaseGameActivity.onCreate(BaseGameActivity.java:82)
        at android.app.Activity.performCreate(Activity.java:5248)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1110)


 at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2162)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2257)
            at android.app.ActivityThread.access$800(ActivityThread.java:139)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1210)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:136)
            at android.app.ActivityThread.main(ActivityThread.java:5086)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:515)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
            at dalvik.system.NativeStart.main(Native Method)

1 个答案:

答案 0 :(得分:2)

我没有使用andEngine,但基于我看到的,可能是因为你在onCreateScene()和onCreateEngineOptions()中为场景和engineoptions返回null。