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 com.example.myapp.R;
其他回答
更改最新的SDK版本,这对我来说是工作
1.单击文件,然后单击项目结构 2.然后选择app 然后点击确定,这对我有用。
我今天升级了gradle版本和gradle插件版本的最新版本,它为我工作。
之后,同步项目与gradle文件。
我也有同样的问题。我尝试了上面提到的大多数其他人,即Gradle同步,验证缓存和重新启动,清洁和重建项目…重新启动android studio,仍然有同样的问题…
这是我的问题,我认为其他人可能也有同样的问题。我在新创建的布局文件的名称上有空格…而不是file_example.xml我是文件_example.xml **(注意文件和_之间的空格)**当你试图找到这个布局文件的引用时,你会遇到一个错误。
我建议您查看您刚刚创建的最新布局文件,稍微重构名称,然后将您的R.layout更改为activity/fragment中的新文件—> 然后清理..重建项目,项目将编译没有任何错误。至少对我来说,这是解决问题的办法。
只需从根包中导入R符号
import rootpackage.R;
没有重建,同步或其他事情…
我受够了
我可绘制资源中的一个大写字母。 导入安卓。R由Android Studio(或Eclipse)添加 xml文件错误
推荐文章
- 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
- 按钮背景是透明的