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 studio版本0.8.9出现相同的错误(无法解析符号R)后,我所做的是去文件->项目结构,并将JDK的位置更改为我手动安装的oracle JDK。在我的例子中,在linux中,而不是预设的/usr/lib/jvm/java-7-oracle。我将其更改为/home/phvz/App/jdk1.8.0_20保存了设置,R符号问题立即得到了修复

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

在我的例子中,当我试图从另一个包调用R时,出现了这个错误。导入R包解决了我的问题。

import com.mtdaps.yourapp.R;

这不是错误。 如果你有错误 关闭项目。 然后打开项目 在此之后,您可以得到一个错误

Cannot resolve symbol 'default_web_client_id'

可以通过在sting值中插入Web客户端ID来解决