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工作室修复了这个问题。
其他回答
更改最新的SDK版本,这对我来说是工作
1.单击文件,然后单击项目结构 2.然后选择app 然后点击确定,这对我有用。
只需从根包中导入R符号
import rootpackage.R;
没有重建,同步或其他事情…
我今天升级了gradle版本和gradle插件版本的最新版本,它为我工作。
之后,同步项目与gradle文件。
如果你在.xml文件上有任何错误,无论你做什么,你都无法修复这个问题。我建议
-首先,检查XML文件以查找任何错误和
-秒查找事件日志什么Android工作室捕捉到的错误,它会告诉你哪个文件和错误在哪里。
这就是我解决R问题的方法
这是最近删除的xml造成的 在Android Studio中,从这些xml中清除你的项目,选择: Build ->清洁项目
推荐文章
- 警告:API ' variable . getjavacompile()'已过时,已被' variable . getjavacompileprovider()'取代
- 安装APK时出现错误
- 碎片中的onCreateOptionsMenu
- TextView粗体通过XML文件?
- 如何使线性布局的孩子之间的空间?
- DSL元素android.dataBinding。enabled'已过时,已被'android.buildFeatures.dataBinding'取代
- ConstraintLayout:以编程方式更改约束
- PANIC: AVD系统路径损坏。检查ANDROID_SDK_ROOT值
- 如何生成字符串类型的buildConfigField
- Recyclerview不调用onCreateViewHolder
- Android API 21工具栏填充
- Android L中不支持操作栏导航模式
- 如何在TextView中添加一个子弹符号?
- PreferenceManager getDefaultSharedPreferences在Android Q中已弃用
- 在Android Studio中创建aar文件