AndroidApplication类扩展了android活动类,然后它为什么会出现以下错误:
06-06 05:47:17.610: E/AndroidRuntime(12567): java.lang.RuntimeException: Unable to resume activity {com.badlogic.drop/com.badlogic.drop.MainActivity}: java.lang.NullPointerException
06-06 05:47:17.610: E/AndroidRuntime(12567): at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2288)
06-06 05:47:17.610: E/AndroidRuntime(12567): at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2316)
06-06 05:47:17.610: E/AndroidRuntime(12567): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1836)
06-06 05:47:17.610: E/AndroidRuntime(12567): at android.app.ActivityThread.access$500(ActivityThread.java:122)
06-06 05:47:17.610: E/AndroidRuntime(12567): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1024)
06-06 05:47:17.610: E/AndroidRuntime(12567): at android.os.Handler.dispatchMessage(Handler.java:99)
06-06 05:47:17.610: E/AndroidRuntime(12567): at android.os.Looper.loop(Looper.java:132)
06-06 05:47:17.610: E/AndroidRuntime(12567): at android.app.ActivityThread.main(ActivityThread.java:4123)
06-06 05:47:17.610: E/AndroidRuntime(12567): at java.lang.reflect.Method.invokeNative(Native Method)
06-06 05:47:17.610: E/AndroidRuntime(12567): at java.lang.reflect.Method.invoke(Method.java:491)
06-06 05:47:17.610: E/AndroidRuntime(12567): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
06-06 05:47:17.610: E/AndroidRuntime(12567): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
06-06 05:47:17.610: E/AndroidRuntime(12567): at dalvik.system.NativeStart.main(Native Method)
06-06 05:47:17.610: E/AndroidRuntime(12567): Caused by: java.lang.NullPointerException
06-06 05:47:17.610: E/AndroidRuntime(12567): at com.badlogic.gdx.backends.android.AndroidApplication.onResume(AndroidApplication.java:223)
06-06 05:47:17.610: E/AndroidRuntime(12567): at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1153)
06-06 05:47:17.610: E/AndroidRuntime(12567): at android.app.Activity.performResume(Activity.java:4468)
06-06 05:47:17.610: E/AndroidRuntime(12567): at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2278)
我将MainActivity类从Activity扩展到AndroidApplication,然后它给出了上述错误。但是当我取消注释评论部分时,它会完美地工作。请帮助解决它。
public class MainActivity extends AndroidApplication {
AndroidApplication app;
LinearLayout m3d;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
/* AndroidApplicationConfiguration config = new AndroidApplicationConfiguration();
config.useGL20 = false;
config.useAccelerometer = false;
config.useCompass = false;
m3d = (LinearLayout) findViewById(R.id.m3d);
View m3dDrop = initializeForView(new Drop(), config);
m3d.addView(m3dDrop); */
}
}
答案 0 :(得分:2)
我猜是因为你没有打电话给initializeForView()
,需要在onCreate()
中调用。 documentation解释说您需要所有注释代码。
要解决这个问题,只需将注释后的代码放回去。为什么甚至将其删除?