1

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); */ 

    }


}
4

1 回答 1

2

我猜这是因为你没有打电话initializeForView(),需要打电话onCreate()。该文档解释说您需要所有注释代码。

要解决,只需将注释的代码放回去。你为什么还要把它拿出来?

于 2012-06-06T17:33:38.487 回答