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.


当前回答

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

其他回答

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

我不得不在android studio中导入我的R包。例如:import com.example。<包名称>。R

这个符号看起来很好用。

android:id="@+id/viewID"

Android Studio的设计面板似乎不太好用。

大多数情况下,此问题是由XML文件引起的,请查看XML文件,查找任何错误。

我也遇到过同样的问题,当我创建一个新项目时,这种情况就会发生。

我所做的是:

检查SDK更新 然后是安卓工作室更新, 然后重新打开项目 打开andoridmanifest.xml 在android:标签中删除“_>”之间的空格并保存。

这对我很有用。