java.lang.NoSuchFieldError: No static field xxx of type I in class Lcom/XX/R$id; or its superclasses
来源:互联网 发布:阿里云栖大会 编辑:程序博客网 时间:2024/06/02 02:18
问题描述
java.lang.NoSuchFieldError: No static field xxx of type I in class Lcom/XX/R$id; or its superclasses
问题分析
首先,在调用 findViewById 之前,必然是在 activity 中设置了setContentView,或者在 Fragment 中重载了onCreatedView 方法,加载了相应的布局文件。对于 activity,findViewById遍历的根节点就是 setContentView 初始化的布局。
安卓在调用findViewById 时会对相应的layout进行遍历查找,如果没有则返回null。同样的NoSuchFieldError是Java反射中的一个异常,其表示无法通过反射找到需要的字段。
那么在布局文件存在,并且包含了所要findViewById的组建的情况下,为什么会报NoSuchFieldError呢?因为一个安卓项目可能包含多个module,在不同的module中可能包含相同名字的布局文件,这种情况下,通过setContentView加载的布局很有可能不是本身module内的布局。
解决方法
多个module的项目中,不应出现多个相同名称的布局文件,有的话重命名一下。
阅读全文
0 0
- java.lang.NoSuchFieldError: No static field xxx of type I in class Lcom/XX/R$id; or its superclasses
- java.lang.NoSuchFieldError: No static field xxx of type I in class Lcom/XX/R$id; or its superclasses
- java.lang.NoSuchFieldError: No static field xxx of type I in class Lcom/XX/R$id; or its superclasses
- AS开发中出现Error(二)——Java.lang.NoSuchFieldError: No static field xxx of type I in class Lcom/XX/R$id; or
- NoSuchFieldError: No static field btn_press3 of type I in class Lcom/hyphenate/helpdesk/R$id; or its
- java.lang.NoSuchFieldError: no "I" field XXXXin class "Lxx/xx/xx/xx;" or its superclasses
- java.lang.NoSuchFieldError: No field title of type I
- java.lang.NoSuchFieldError: No field title of type
- No static field ll_time of type I in class L使用第三方类库R文件不编译
- java.lang.NoSuchFieldError: No static field
- java.lang.NoSuchFieldError:包.R$id.xxx
- android java.lang.NoSuchFieldError: R$id.xxx
- android java.lang.NoSuchFieldError: R$id.xxx
- android java.lang.NoSuchFieldError: R$id.xxx
- android java.lang.NoSuchFieldError: R$id.xxx
- java.lang.NoSuchFieldError:包.R$id.xxx
- android java.lang.NoSuchFieldError: R$id.xxx
- android java.lang.NoSuchFieldError: R$id.xxx 异常
- Unity-UGUI框架<二>
- php 判断手机端访问并设置默认访问模块的方法
- PullToRefresh下拉刷新框架
- 23、不一样的C++系列--智能指针
- 极光推送与IOS实例
- java.lang.NoSuchFieldError: No static field xxx of type I in class Lcom/XX/R$id; or its superclasses
- DTD:定义XML文档的合法构建模块
- 对抗拖库 —— Web 前端慢加密
- 【Java线程】Java线程池ExecutorService--雷锋
- springmvc程序案例1
- Eclipse Memory Analyzer tool(MAT)分析内存泄露(二)
- 使用VS Code开发.Net Core程序
- 操作系统实验报告 lab7
- 11种行为型模式之:观察者模式 (Observer)