安卓幻灯片菜单使用幻灯片菜单库

时间:2013-06-07 08:13:13

标签: android menu slide

我尝试在facebook和youtube应用中创建幻灯片菜单。为此,我使用幻灯片菜单库。现在我创建像enter link description here这样的项目。但是在运行这个项目时会出现错误。该错误称为这行代码

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

logcat的

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

帮助某人解决错误

1 个答案:

答案 0 :(得分:0)

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

我建议阅读 this