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文件出错,然后我解决它。 然后清除该项目。 错误消失了。

其他回答

首先检查是否有任何错误在任何xml布局,如果然后解决它首先。

否则,从项目中删除junit依赖项并重新构建项目。

在我的情况下,原因是有一些图像在res文件夹名称包含一个大写字母..

只要用小写字母重新命名就可以了

上面的答案对我没有帮助。我最终意识到问题在于Android Studio中缺少“build”文件夹。我在项目“iml”文件中发现了一些行,不包括“build/*”。删除这些错误后,生成文件就出现了,错误就消失了。

类型1:关闭项目并删除项目中的.gradle文件 然后重建项目 类型2:如果类型1不起作用,那就把它拿回来 project9Zip文件),然后删除项目。然后提取 压缩项目,只是导入提取的项目,它将工作 很好,因为这对我很管用。

我有我的XML文件在一个布局文件夹,而不是菜单文件夹。

这是我们从Eclipse转移到Android Studio的结果。

解决方案对我来说很简单……将XML文件移动到MENU文件夹并重新编译。