AndEngine 的 NullPointerException
NullPointerException with 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.access0(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.access0(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)
我不使用 andEngine,但根据我所见,这可能是因为您在 onCreateScene() 和 onCreateEngineOptions() 中为场景和引擎选项都返回了 null。
我根据 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.access0(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.access0(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)
我不使用 andEngine,但根据我所见,这可能是因为您在 onCreateScene() 和 onCreateEngineOptions() 中为场景和引擎选项都返回了 null。