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.


当前回答

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

其他回答

如果你在.xml文件上有任何错误,无论你做什么,你都无法修复这个问题。我建议

-首先,检查XML文件以查找任何错误和

-秒查找事件日志什么Android工作室捕捉到的错误,它会告诉你哪个文件和错误在哪里。

这就是我解决R问题的方法

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

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

import com.mtdaps.yourapp.R;

尝试确保完整的包名在第一行。假设您有一个名为LoginActivity.java的文件和一个名为com.domainname.project的包。

java的第一行应该是

package com.domainname.project;

这相当于在dot.net中指定“namespace”。还要确保该包与包含*.java文件的包匹配。

我受够了

我可绘制资源中的一个大写字母。 导入安卓。R由Android Studio(或Eclipse)添加 xml文件错误