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.


当前回答

你的代码被打乱了。答案相当简单。

点击构建->清洁项目。

这样应该可以了。

检查你的Android Studio版本。

我目前使用的是Android Studio 3.0.1。

其他回答

我受够了

我可绘制资源中的一个大写字母。 导入安卓。R由Android Studio(或Eclipse)添加 xml文件错误

在我的情况下:res/someLayout.xml文件出错,然后我解决它。 然后清除该项目。 错误消失了。

在最新版本的Android Studio中,至少对我来说,如下作品:

“工具”->“Android”->“同步项目与Gradle文件”

在最新的Android Studio 3.1.3(2018年7月)中,“同步项目与Gradle文件”在主菜单栏中可用。

做:建立>清洁项目

重要:确保在消息窗格(Alt+0)中清除项目后没有任何错误。如果您发现任何带有感叹号的红色圆圈,那么您必须删除代码中的这些错误。

这些错误大多与@string/或@array/有关。再次清洁项目,完成!

这让我很头疼。在我的案例中,在Android Studio中配置“谷歌播放服务”后出现了错误(安装+ build。gradle配置)。这反过来需要minsdk > 7,但错误是非常不清楚的(实际上一个抱怨这只出现为“信息”)。总之. .在清单文件和构建中将minsdk更改为8。Gradle文件和重建项目,错误消失了。

所以. .关于这一点,如果我可以概括的话,你可能在你的清单文件或其他配置文件中有一些问题,这阻碍了正确的构建。试着仔细查看错误报告,甚至是标题为“info”的消息,以寻找任何关于它可能是什么的提示……