In every instance in all of my classes where I reference R.id.something, the R is in red and it says "cannot resolve symbol R". Also every time there is R.layout.something it is underlined in red and says "cannot resolve method setContentView(?)". The project always builds fine. It is annoying to see this all the time. I have read many other questions on here about something similar but most involved importing projects from Eclipse. I am using what I believe to be the most recent version of Android Studio and the project was created with Android Studio and worked without any "cannot resolve R" problems. I would like to know what causes this if anyone knows.
当前回答
在我的情况下:res/someLayout.xml文件出错,然后我解决它。 然后清除该项目。 错误消失了。
其他回答
在一个非基础特性的即时应用活动中,你可以调用R.id.fromFeatureOne和R.is.fromFeatureTwo。因此,来自不同资源的项目被引用为单一资源来源。
两者都将被高亮显示为可接受的,您甚至可以跳转到源代码。但是构建会导致一个错误:“不能找到符号R.id”,这是相当棘手的原因,因为什么都没有突出显示。
解决方案是调用com.example.feature.one.R.is.fromFeatureOne和com.example.feature.two.R.is.fromFeatureTwo。
在谷歌:https://issuetracker.google.com/u/0/issues/77537714也发布了一个bug
R.java文件包含xml和java页面之间的链接。只有在某些资源文件出现问题时,才会出现“R无法解决”。因此,最好和有效的方法是删除最后完成的xml或绘制在res文件。然后再根据android编码规范从那里开始。这是唯一的办法。有效而正确的方法。
也可以使用Git来正确地跟踪代码。
我也遇到过同样的问题,大多数时候都是通过
同步项目与gradle文件 做构建->清洁项目 Doing File ->使缓存失效
但这一次,即使在做了所有这些事情后,错误仍然存在,最后我找到了罪魁祸首。
问题是在一个xml文件,在那里我给了一个普通的字符串值为android:id而不是id资源类型。
错误
android:id="username"
修正
android:id="@id/username"
混淆xml文件中与资源相关的内容是一个主要问题 此错误的原因。注意,它可能不会在xml布局文件中显示为错误。
请注意
在大多数情况下,编译器会在消息中显示错误的来源。 在尝试其他解决方案之前,请先检查它
我也有这个问题。简单的“gradlew clean”和“gradlew build”就成功了。
点击Build->Clean Project,将执行gradle Clean
我受够了
我可绘制资源中的一个大写字母。 导入安卓。R由Android Studio(或Eclipse)添加 xml文件错误
推荐文章
- 在应用程序本身中更改Locale
- apk (.apk)和应用程序包(.aab)的区别
- 如何设置超时在改造库?
- Android - SPAN_EXCLUSIVE_EXCLUSIVE跨度不能为零长度
- TextView的字体大小在Android应用程序改变字体大小从本机设置
- 如何模拟Android杀死我的进程
- 禁用EditText闪烁光标
- Android Eclipse -无法找到*.apk
- 设置TextView文本从html格式的字符串资源在XML
- 如何允许所有网络连接类型HTTP和HTTPS在Android(9)馅饼?
- Android加载JS包失败
- Android Studio, logcat在应用程序关闭后清理
- 在android中从上下文获取活动
- 无法解析主机"<URL here>"没有与主机名关联的地址
- getActivity()在Fragment函数中返回null