我从Links下载了Sliding Menu库和Actionsbarsherlock,并从example找到了一个示例,其中有一个YouTube视频link来显示其工作原理。我遵循了所有步骤,但是当我运行代码时,它给了我。
05-28 15:41:21.665: E/AndroidRuntime(2023): FATAL EXCEPTION: main
05-28 15:41:21.665: E/AndroidRuntime(2023): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.rufflez.slidingmenuexample/com.rufflez.slidingmenuexample.MainActivity}: java.lang.IllegalStateException: RandomList must be attached to a SherlockFragmentActivity.
05-28 15:41:21.665: E/AndroidRuntime(2023): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956)
05-28 15:41:21.665: E/AndroidRuntime(2023): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
05-28 15:41:21.665: E/AndroidRuntime(2023): at android.app.ActivityThread.access$600(ActivityThread.java:123)
05-28 15:41:21.665: E/AndroidRuntime(2023): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
05-28 15:41:21.665: E/AndroidRuntime(2023): at android.os.Handler.dispatchMessage(Handler.java:99)
05-28 15:41:21.665: E/AndroidRuntime(2023): at android.os.Looper.loop(Looper.java:137)
05-28 15:41:21.665: E/AndroidRuntime(2023): at android.app.ActivityThread.main(ActivityThread.java:4424)
05-28 15:41:21.665: E/AndroidRuntime(2023): at java.lang.reflect.Method.invokeNative(Native Method)
05-28 15:41:21.665: E/AndroidRuntime(2023): at java.lang.reflect.Method.invoke(Method.java:511)
05-28 15:41:21.665: E/AndroidRuntime(2023): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791)
05-28 15:41:21.665: E/AndroidRuntime(2023): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:558)
05-28 15:41:21.665: E/AndroidRuntime(2023): at dalvik.system.NativeStart.main(Native Method)
05-28 15:41:21.665: E/AndroidRuntime(2023): Caused by: java.lang.IllegalStateException: RandomList must be attached to a SherlockFragmentActivity.
05-28 15:41:21.665: E/AndroidRuntime(2023): at com.actionbarsherlock.app.SherlockListFragment.onAttach(SherlockListFragment.java:25)
05-28 15:41:21.665: E/AndroidRuntime(2023): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:867)
05-28 15:41:21.665: E/AndroidRuntime(2023): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1088)
05-28 15:41:21.665: E/AndroidRuntime(2023): at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:682)
05-28 15:41:21.665: E/AndroidRuntime(2023): at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1444)
05-28 15:41:21.665: E/AndroidRuntime(2023): at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:551)
05-28 15:41:21.665: E/AndroidRuntime(2023): at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1133)
05-28 15:41:21.665: E/AndroidRuntime(2023): at android.app.Activity.performStart(Activity.java:4475)
05-28 15:41:21.665: E/AndroidRuntime(2023): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1929)
05-28 15:41:21.665: E/AndroidRuntime(2023): ... 11 more
不知道为什么会出现错误,我也添加了两个库。
最佳答案
问题:
java.lang.IllegalStateException: RandomList must be attached to a SherlockFragmentActivity
解:
您需要扩展SherlockActivity
参考:
看看SlidingMenu usage guide,
阅读如何将这个库集成到您的项目中的步骤2的最后一点
“如果要使用其他库(例如ActionBarSherlock),则可以更改SlidingActivities以扩展SherlockActivities,而不是常规的Activity”。
说明:
如上面的屏幕截图所示,
SlidingActivity extends SherlockActivity
。同样,需要进行以下更改,
- SlidingListActivity extends SherlockListActivity
- SlidingFragmentActivity extends SherlockFragmentActivity
- SlidingPreferenceActivity extends SherlockPreferenceActivity
注意:
不要忘记将
actionbarsherlock
库添加到SlidingMenu的库中以访问SherlockActivity
。我希望这会有所帮助!