简体   繁体   English

ActionBarSherlock类型mAdded无法解析或不是字段Watson.java

[英]ActionBarSherlock Type mAdded cannot be resolved or is not a field Watson.java

I spended a day looking for solution for this error I downloaded ActionBarSherlock and import library to eclipse I had fixed all errors and this is the last one I Checked all layouts there is no xml error, Cleaned workspace and restarted eclipse 我花了一天寻找这个错误的解决方案我下载ActionBarSherlock并导入库到eclipse我修复了所有错误,这是最后一个我检查所有布局没有xml错误,清理工作区并重新启动eclipse

this is error descrition : 这是错误描述:

Description Resource Path Location Type mAdded cannot be resolved or is not a field Watson.java /abs_library/src/android/support/v4/app line 59 Java Problem 说明资源路径位置类型mAdded无法解析或不是字段Watson.java / abs_library / src / android / support / v4 / app line 59 Java问题

The code 代码

if (mFragments.mAdded != null) {
                for (int i = 0; i < mFragments.mAdded.size(); i++) {
                    Fragment f = mFragments.mAdded.get(i);
                    if (f != null && !f.mHidden && f.mHasMenu && f.mMenuVisible
                            && f instanceof OnCreateOptionsMenuListener) {
                        show = true;
                        ((OnCreateOptionsMenuListener) f).onCreateOptionsMenu(
                                menu, inflater);
                        if (newMenus == null) {
                            newMenus = new ArrayList<Fragment>();
                        }
                        newMenus.add(f);
                    }
                }
            }

Thank you 谢谢

if you updated your android-support-v4.jar, just replace these three lines of code 如果您更新了android-support-v4.jar,只需替换这三行代码即可

if (mFragments.mAdded != null) {
   for (int i = 0; i < mFragments.mAdded.size(); i++) {
      Fragment f = mFragments.mAdded.get(i);

with

List<Fragment> actives =  mFragments.getActiveFragments(null);
if (actives != null) {
   for (int i = 0; i < actives.size(); i++) {
       Fragment f = actives.get(i);

... ...

everything will be ok. 一切都会好起来的。

I found a solution: 1# download SherlockActionBar sources from here: https://github.com/JakeWharton/ActionBarSherlock/releases 2# if you're using android-support-v4.jar in your project (as I am) -> replace it from ZIP #1 (you can find it in 'libs' folder) It helps me. 我找到了一个解决方案:1#从这里下载SherlockActionBar来源: https//github.com/JakeWharton/ActionBarSherlock/releases 2#如果你在你的项目中使用android-support-v4.jar(就像我一样) - >从ZIP#1替换它(你可以在'libs'文件夹中找到它)它对我有所帮助。

Note: I had 2 versions of android-support-v4.jar in my project: 注意:我的项目中有2个版本的android-support-v4.jar:

  1. from AndroidSDK (extras~>android~>v4) // work with the error 来自AndroidSDK(extras~> android~> v4)// 使用错误
  2. from SherlockActionBar // works ok here 来自SherlockActionBar // 在这里工作正常

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM