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.
当前回答
建立>清洁项目
这对我很管用。同样的问题我也遇到过几次,这似乎解决了问题。除非你改变了一些东西或变量r,这个问题通常是突然发生的,当它发生在我身上时,所以我想这只是Android工作室吓坏了。哈哈
祝你过得愉快,并祝你的项目好运。
其他回答
在我的例子中,当我试图从另一个包调用R时,出现了这个错误。导入R包解决了我的问题。
import com.mtdaps.yourapp.R;
我在清理建筑。Gradle和这个错误出现。
一大堆“清理和重建”的答案。这些对我都没用。
最后,我发现我无意中复制粘贴了build.gradle中错误的“命名空间”名称。修复了它,它运行。
在我的情况下,我试图清理和重建项目。这个问题没有修复,因为在布局文件中存在错误。为了重新创建,我在应用程序名称空间的属性上添加了一个错字。
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/add_user"
android:icon="@android:drawable/ic_menu_add"
android:title="Add User"
app:showAsActioin="always"
/>
</menu>
Android工作室没有检查应用程序名称空间的属性,似乎文件是无错误的。现在,在构建项目时,它说无法解析符号“R”。错误显示在构建日志中。
修复错字修复它,手表上的Android问题部分的构建日志。
我受够了
我可绘制资源中的一个大写字母。 导入安卓。R由Android Studio(或Eclipse)添加 xml文件错误
只需进入Android Top菜单列表。点击构建菜单,在构建下点击重建项目。
推荐文章
- 我可以设置“android:layout_below”在运行时编程?
- Android Studio谷歌JAR文件导致GC开销限制超过错误
- 为什么每当我创建一个新项目时,Eclipse都会自动添加appcompat v7库支持?
- 如何同步项目到GitHub与Android工作室?
- Keytool错误:java.io。IoException:错误的AVA格式
- GCM与PHP(谷歌云消息传递)
- 自定义圆圈按钮
- 我如何使用一个复合绘图而不是一个线性布局,包含一个ImageView和一个TextView
- 如何绘制一个线性布局的边界
- 如何动画添加或删除Android列表视图行
- 如何解决“丢失的PendingIntent可变性标志”在android api 30+ lint警告?
- 我怎么能修复“意外元素<查询>发现<manifest>”错误?
- Android房间-自动生成新插入行的id
- Android Studio在哪里保存ProGuard映射文件?
- 我如何从资产文件夹解析一个本地JSON文件到一个ListView?