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符号
import rootpackage.R;
没有重建,同步或其他事情…
其他回答
我正面临一个错误“无法解析符号R” java文件中的R显示为红色。我已经解出来了。
不保存任何大写字母的图像 像ABC.png。 首先删除映像或重命名它。 清洁项目 重建项目
做:建立>清洁项目
重要:确保在消息窗格(Alt+0)中清除项目后没有任何错误。如果您发现任何带有感叹号的红色圆圈,那么您必须删除代码中的这些错误。
这些错误大多与@string/或@array/有关。再次清洁项目,完成!
只需清理你的项目和同步项目与Gradle文件。
问题会得到解决。
当我手动重命名应用程序的域文件夹时,我遇到了这个问题。为了解决这个问题,我不得不这样做
在AndroidManifest.xml中设置正确的<manifest>的包文件夹结构。 在AndroidManifest.xml中为android设置新的包位置:<activity>的名称。 清除缓存
文件菜单-> Invalidate cache / Restart…
一旦Android工作室重新启动并构建新的索引,这个问题就会消失。
在我的情况下:res/someLayout.xml文件出错,然后我解决它。 然后清除该项目。 错误消失了。
推荐文章
- 在应用程序本身中更改Locale
- apk (.apk)和应用程序包(.aab)的区别
- 如何设置超时在改造库?
- Android - SPAN_EXCLUSIVE_EXCLUSIVE跨度不能为零长度
- TextView的字体大小在Android应用程序改变字体大小从本机设置
- 如何模拟Android杀死我的进程
- 禁用EditText闪烁光标
- Android Eclipse -无法找到*.apk
- 设置TextView文本从html格式的字符串资源在XML
- 如何允许所有网络连接类型HTTP和HTTPS在Android(9)馅饼?
- Android加载JS包失败
- Android Studio, logcat在应用程序关闭后清理
- 在android中从上下文获取活动
- 无法解析主机"<URL here>"没有与主机名关联的地址
- getActivity()在Fragment函数中返回null