0

我尝试在 facebook 和 youtube 应用程序中创建幻灯片菜单。为此,我使用幻灯片菜单库。现在我创建项目,如在此处输入链接描述。但是运行这个项目时出现错误。错误调用这行代码

if (savedInstanceState == null) 
        {
            FragmentTransaction t = this.getSupportFragmentManager().beginTransaction();
            mFrag = new RandomList();
            t.replace(R.id.menu_frame, mFrag);
            t.commit();
        }

日志猫

06-07 11:01:27.318: E/AndroidRuntime(1627): FATAL EXCEPTION: main
06-07 11:01:27.318: E/AndroidRuntime(1627): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.jlabproject/com.example.jlabproject.MainActivity}: java.lang.IllegalStateException: Activity has been destroyed
06-07 11:01:27.318: E/AndroidRuntime(1627):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
06-07 11:01:27.318: E/AndroidRuntime(1627):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
06-07 11:01:27.318: E/AndroidRuntime(1627):     at android.app.ActivityThread.access$600(ActivityThread.java:141)
06-07 11:01:27.318: E/AndroidRuntime(1627):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
06-07 11:01:27.318: E/AndroidRuntime(1627):     at android.os.Handler.dispatchMessage(Handler.java:99)
06-07 11:01:27.318: E/AndroidRuntime(1627):     at android.os.Looper.loop(Looper.java:137)
06-07 11:01:27.318: E/AndroidRuntime(1627):     at android.app.ActivityThread.main(ActivityThread.java:5041)
06-07 11:01:27.318: E/AndroidRuntime(1627):     at java.lang.reflect.Method.invokeNative(Native Method)
06-07 11:01:27.318: E/AndroidRuntime(1627):     at java.lang.reflect.Method.invoke(Method.java:511)
06-07 11:01:27.318: E/AndroidRuntime(1627):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
06-07 11:01:27.318: E/AndroidRuntime(1627):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
06-07 11:01:27.318: E/AndroidRuntime(1627):     at dalvik.system.NativeStart.main(Native Method)
06-07 11:01:27.318: E/AndroidRuntime(1627): Caused by: java.lang.IllegalStateException: Activity has been destroyed
06-07 11:01:27.318: E/AndroidRuntime(1627):     at android.support.v4.app.FragmentManagerImpl.enqueueAction(FragmentManager.java:1314)
06-07 11:01:27.318: E/AndroidRuntime(1627):     at android.support.v4.app.BackStackRecord.commitInternal(BackStackRecord.java:541)
06-07 11:01:27.318: E/AndroidRuntime(1627):     at android.support.v4.app.BackStackRecord.commit(BackStackRecord.java:525)
06-07 11:01:27.318: E/AndroidRuntime(1627):     at com.example.jlabproject.BaseActivity.onCreate(BaseActivity.java:42)
06-07 11:01:27.318: E/AndroidRuntime(1627):     at com.example.jlabproject.MainActivity.onCreate(MainActivity.java:28)
06-07 11:01:27.318: E/AndroidRuntime(1627):     at android.app.Activity.performCreate(Activity.java:5104)
06-07 11:01:27.318: E/AndroidRuntime(1627):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
06-07 11:01:27.318: E/AndroidRuntime(1627):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
06-07 11:01:27.318: E/AndroidRuntime(1627):     ... 11 more

帮助某人了解问题所在

4

1 回答 1

0

我猜你是在创建活动之前提交片段。试试你的代码onActivityCreated()

我推荐阅读 这个

于 2013-06-07T08:50:25.537 回答