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.
当前回答
显然,在我的例子中,这个问题通过在结尾添加一个“*”得到了解决
import android.R.*;
其他回答
我正面临一个错误“无法解析符号R” java文件中的R显示为红色。我已经解出来了。
不保存任何大写字母的图像 像ABC.png。 首先删除映像或重命名它。 清洁项目 重建项目
当我手动重命名应用程序的域文件夹时,我遇到了这个问题。为了解决这个问题,我不得不这样做
在AndroidManifest.xml中设置正确的<manifest>的包文件夹结构。 在AndroidManifest.xml中为android设置新的包位置:<activity>的名称。 清除缓存
文件菜单-> Invalidate cache / Restart…
一旦Android工作室重新启动并构建新的索引,这个问题就会消失。
在我的案例中,通过将Android Studio从3.1更新到3.3解决了这个问题
要更新您的Android Studio:文件->设置->系统设置->更新,然后点击立即检查。
上面的答案对我没有帮助。我最终意识到问题在于Android Studio中缺少“build”文件夹。我在项目“iml”文件中发现了一些行,不包括“build/*”。删除这些错误后,生成文件就出现了,错误就消失了。
对我来说,问题是我升级到一个似乎有一些bug的Gradle版本。3.4.0-alpha02是我更新到的,发现这是“无法解析符号R”错误的罪魁祸首。我恢复到3.3.0-alpha10(即类路径'com.android.tools.build:gradle:3.3.0-alpha10'),它解决了这个问题。
这显然不是一个持久的解决方案,因为我迟早需要升级,但截至2018年11月3日,3.4.0-alpha02是最新版本,它阻碍了我的开发,因为它不允许我通过单击R引用在IDE中跳跃。
推荐文章
- Android Studio中的。iml文件是什么?
- 如何在新的材质主题中改变背面箭头的颜色?
- androidviewpager与底部点
- 相同的导航抽屉在不同的活动
- 如何从视图中获得托管活动?
- 单一的TextView与多种颜色的文本
- 如何在非活动类(LocationManager)中使用getSystemService ?
- 在清单中注册应用程序类?
- Android:从数组中编程创建旋转器
- Android命令行工具sdkmanager总是显示:警告:无法创建设置
- 如何设置RecyclerView应用程序:layoutManager=""从XML?
- 在没有开发服务器的情况下在设备上构建和安装unsigned apk ?
- 操作栏和新引入的工具栏有什么不同?
- 调整浮动动作按钮图标大小(fab)
- Android Studio无法找到有效的Jvm(与MAC OS相关)