gpt4 book ai didi

android - 滑动菜单示例不工作 : java. lang.IllegalStateException:RandomList 必须附加到 SherlockFragmentActivity

转载 作者:行者123 更新时间:2023-11-29 21:42:08 27 4
gpt4 key购买 nike

我从 Links 下载了滑动菜单库和 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

不知道为什么会出现错误,我也添加了这两个库。

libraries added

最佳答案

问题:

java.lang.IllegalStateException: RandomList must be attached to a SherlockFragmentActivity

解决方案:

你需要扩展 SherlockActivity

引用:

看看SlidingMenu usage guide ,

阅读如何将此库集成到您的项目部分中第 2 步的最后一点

“如果您想使用其他库,例如 ActionBarSherlock,您只需更改 SlidingActivities 以扩展 SherlockActivities 而不是常规 Activity ”

解释:

enter image description here

如上图所示,

SlidingActivity 扩展 SherlockActivity

同样需要进行如下改动,

 - SlidingListActivity extends SherlockListActivity
- SlidingFragmentActivity extends SherlockFragmentActivity
- SlidingPreferenceActivity extends SherlockPreferenceActivity

注意:不要忘记将 actionbarsherlock 库添加到 SlidingMenu 的库中以访问 SherlockActivity

希望对您有所帮助!!

关于android - 滑动菜单示例不工作 : java. lang.IllegalStateException:RandomList 必须附加到 SherlockFragmentActivity,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16790187/

27 4 0