我下载滑动菜单库,并从Actionsbarsherlock 链接,我发现的例子,从它的例如,其中有一个YouTube影片的链接以显示工作。我跟所有的步骤,但是当我运行code,它给我。
I downloaded Sliding Menu library and Actionsbarsherlock from Links, I found out example of it from example, which had an YouTube video link to show the working. I followed all the steps, but when I am running the code, its giving me.
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
不知道为什么错误来了,我有加两个库也。
No idea why the error is coming, I have add both libraries also.
问题:
java.lang.IllegalStateException: RandomList must be attached to a SherlockFragmentActivity
解决方案:
您需要延长SherlockActivity
you need to extend SherlockActivity
参考:
看一看 SlidingMenu使用指南,
步骤2的内侧部分阅读最后一点如何到这个库集成到您的项目
read last point of Step 2 inside section of How to Integrate this Library into Your Projects
如果你想使用其他库如ActionBarSherlock,你可以改变SlidingActivities延长SherlockActivities,而不是常规的活动
"If you want to use another library such as ActionBarSherlock, you can just change the SlidingActivities to extend the SherlockActivities instead of the regular Activities"
释解:
如图上面的截图,
SlidingActivity延伸SherlockActivity
。
同样如下更改,
- SlidingListActivity extends SherlockListActivity
- SlidingFragmentActivity extends SherlockFragmentActivity
- SlidingPreferenceActivity extends SherlockPreferenceActivity
注意:不要忘了 actionbarsherlock
库添加到您的SlidingMenu的图书馆访问 SherlockActivity
。
Note:
Don't forget to add actionbarsherlock
library to your SlidingMenu's library to access SherlockActivity
.
我希望这会有所帮助!