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.


当前回答

     The above answers are also the ways to fix the error but if does not work for anyone  then i have an option...

只需要关闭项目,然后重新启动它,这样它就会加载引用… 跟着截图走。

其他回答

只需清理你的项目和同步项目与Gradle文件。

问题会得到解决。

确保项目中有AndroidManifest.xml。

我导入的项目还没有manifest,所以Android Studio不会将其识别为Android项目。然后我在GIT中拉了这个项目,它下载了清单,但仍然不能工作。 然后我重新启动Android Studio,它说“框架检测到Android”。

确保你的项目配置为Android项目。

     The above answers are also the ways to fix the error but if does not work for anyone  then i have an option...

只需要关闭项目,然后重新启动它,这样它就会加载引用… 跟着截图走。

当我导入google服务时,我就遇到了这个问题。json文件来实现分析。我已经在xml文件夹中有global_tracker.xml文件。在构建过程中,合并来自google-services的内容。Json文件,错误开始发生。

删除google -services后,该错误得到解决。json文件。

我在可绘制资源中添加了一些图像,其中一个图像被命名为“super.jpg”,这是一个原因。

重命名图像并在此之后将项目与gradle文件同步修复了错误。