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.


当前回答

只需从根包中导入R符号

import rootpackage.R;

没有重建,同步或其他事情…

其他回答

只需进入Android Top菜单列表。点击构建菜单,在构建下点击重建项目。

我自己也费了好大劲才搞定的。

确保layout.xml文件中没有错误。 转到构建>清洁项目

这招对我管用,希望对你也管用。

我正面临一个错误“无法解析符号R” java文件中的R显示为红色。我已经解出来了。

不保存任何大写字母的图像 像ABC.png。 首先删除映像或重命名它。 清洁项目 重建项目

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

点击构建->清洁项目。

这样应该可以了。

检查你的Android Studio版本。

我目前使用的是Android Studio 3.0.1。

在OS X和Android Studio 0.2.13上,我在com上做了“跳转到声明”。<项目>。在我的活动之一。当我回到活动文件时,所有的警告都消失了。

编辑:在此工作之前,您需要构建当前的构建变体。