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)


我将Activity从MainActivity类扩展到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); */

    }


}

最佳答案

我猜这是因为您没有调用initializeForView(),需要在onCreate()中调用它。 documentation说明您需要所有这些注释的代码。

要解决此问题,只需将已注释的代码放回去。您为什么还要将其取出?

10-07 23:15