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工作室修复了这个问题。
“我也遇到过同样的问题,解决方法是:
1) Sync Project with gradle files
2) Build -> Clean Project
3) Build -> Rebuild Project
4) File -> Invalidate caches
//imp step
5) Check your xml files properly.`
我也有同样的问题: Android Studio 3.2 该项目编译和运行良好,但我在屏幕上得到“无法解析符号“R”的警告
没有帮助:
构建——>清洁项目 构建- >重建项目 文件- >缓存失效/重新启动
帮助:
要么
在build.gradle
dependencies {
classpath 'com.android.tools.build:gradle:3.3.0'
...
}
替换为
dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
...
}
or
更新Android Studio到3.3
在我做“建立->清洁项目”和“同步项目与gradle”。它们都不是解。我从3.3.0 => 3.2.1(恢复为项目初始状态)下构建gradle版本,它解决了我的问题。
在xml文件中简单地定义一个应用程序名称空间就会导致这种情况。这是一个完全无害的行,只选择了一个符号(从许多符号中)来解析。简单地删除整行,在下面的图片中灰色,使我的代码引用未解析的符号。甚至当我添加回线,它决定没有问题。图。
推荐文章
- Android Studio中的。iml文件是什么?
- 如何在新的材质主题中改变背面箭头的颜色?
- androidviewpager与底部点
- 相同的导航抽屉在不同的活动
- 如何从视图中获得托管活动?
- 单一的TextView与多种颜色的文本
- 如何在非活动类(LocationManager)中使用getSystemService ?
- 在清单中注册应用程序类?
- Android:从数组中编程创建旋转器
- Android命令行工具sdkmanager总是显示:警告:无法创建设置
- 如何设置RecyclerView应用程序:layoutManager=""从XML?
- 在没有开发服务器的情况下在设备上构建和安装unsigned apk ?
- 操作栏和新引入的工具栏有什么不同?
- 调整浮动动作按钮图标大小(fab)
- Android Studio无法找到有效的Jvm(与MAC OS相关)