android java.lang.NoSuchFieldError: R$id.xxx

第一种情况 参考自http://www.shangxueba.com/jingyan/1856083.html

    将引用的自定义控件的xml文件中的最外层布局上面添加xmlns:sat=“http://schemas.android.com/apk/res/控件所在位置的包名”可是在运行时就会报java.lang.NoSuchFieldError:包.R$id.xxx错。同时还会出现no resource identifier found for attribute 的错误。

    将xmlns:sat=“http://schemas.android.com/apk/res/控件所在位置的包名”更改为

    http://schemas.android.com/apk/res-auto 就不会报错了

第二种 参考:http://www.hankcs.com/program/mobiledev/e-androidruntime-fatal-exception-main-java-lang-nosuchfielderror.html

这个问题是由于主项目覆盖了库项目的xml所致,如果主项目中的某个xml里定义了一个跟库项目中的xml同名的xml,那么库中的xml将会被覆盖。这里的覆盖意思是,编译后只有主项目中的xml以及R.id,完全没有库项目的影子。所以才会有NoSuchFieldError的错误。

这个错误不会在编译的时候提示,算得上一个陷阱了。

解决方法很简单,删除主项目中的xml,整个项目只保留一份xml即可。


http://www.eoeandroid.com/forum.php?mod=viewthread&tid=554097



猜你喜欢

转载自blog.csdn.net/zgf1991/article/details/47106235