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由Android Studio(或Eclipse)添加 xml文件错误

其他回答

这是最近删除的xml造成的 在Android Studio中,从这些xml中清除你的项目,选择: Build ->清洁项目

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

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

只需从根包中导入R符号

import rootpackage.R;

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

R.java文件包含xml和java页面之间的链接。只有在某些资源文件出现问题时,才会出现“R无法解决”。因此,最好和有效的方法是删除最后完成的xml或绘制在res文件。然后再根据android编码规范从那里开始。这是唯一的办法。有效而正确的方法。

也可以使用Git来正确地跟踪代码。

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

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

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