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.


当前回答

你可以删除一个布局文件(不管哪个),之后你需要构建项目。在我的情况下,如果我试图在删除布局文件之前构建我的项目,它没有帮助我。但是这样也可以。

其他回答

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

更改最新的SDK版本,这对我来说是工作

1.单击文件,然后单击项目结构 2.然后选择app 然后点击确定,这对我有用。

建立>清洁项目

这对我很管用。同样的问题我也遇到过几次,这似乎解决了问题。除非你改变了一些东西或变量r,这个问题通常是突然发生的,当它发生在我身上时,所以我想这只是Android工作室吓坏了。哈哈

祝你过得愉快,并祝你的项目好运。

在我的情况下:res/someLayout.xml文件出错,然后我解决它。 然后清除该项目。 错误消失了。

这让我很头疼。在我的案例中,在Android Studio中配置“谷歌播放服务”后出现了错误(安装+ build。gradle配置)。这反过来需要minsdk > 7,但错误是非常不清楚的(实际上一个抱怨这只出现为“信息”)。总之. .在清单文件和构建中将minsdk更改为8。Gradle文件和重建项目,错误消失了。

所以. .关于这一点,如果我可以概括的话,你可能在你的清单文件或其他配置文件中有一些问题,这阻碍了正确的构建。试着仔细查看错误报告,甚至是标题为“info”的消息,以寻找任何关于它可能是什么的提示……