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.
当前回答
如果你在移动java文件或目录到其他位置后看到这个错误,那么你可以保证Android Studio已经混淆了。你猜怎么着?撤销这些操作并不能解决问题。
所以你试着戒毒,但没用。
重启也不行。
但是试试文件->无效缓存/重新启动…->失效并重启
Android Studio维护哪些文件依赖于哪些其他文件的信息。由于移动文件没有正确实现,因此移动文件会导致错误。这还不是全部:这些依赖项的缓存被用于加速构建。
这意味着您不仅必须重新启动,而且还需要使这些缓存失效以恢复(或者更准确地说,重新构建)正常运行。
其他回答
在最新版本的Android Studio中,至少对我来说,如下作品:
“工具”->“Android”->“同步项目与Gradle文件”
在最新的Android Studio 3.1.3(2018年7月)中,“同步项目与Gradle文件”在主菜单栏中可用。
//有时由于不完全同步会产生问题
//所以只要按照步骤,它会做你的工作肯定
Click on Build->Clean Project and that will perform a gradle clean
我自己也费了好大劲才搞定的。
确保layout.xml文件中没有错误。 转到构建>清洁项目
这招对我管用,希望对你也管用。
更改最新的SDK版本,这对我来说是工作
1.单击文件,然后单击项目结构 2.然后选择app 然后点击确定,这对我有用。
我已经做了其他答案中提到的所有步骤,但它仍然没有得到解决。我正在使用android工作室花栗鼠,最后我能够通过删除来解决这个问题
maven { url "https://jitpack.io" }
从设置。gradle我在回答这个问题,我认为这样做可能会帮助到一些人
推荐文章
- 我可以设置“android:layout_below”在运行时编程?
- Android Studio谷歌JAR文件导致GC开销限制超过错误
- 为什么每当我创建一个新项目时,Eclipse都会自动添加appcompat v7库支持?
- 如何同步项目到GitHub与Android工作室?
- Keytool错误:java.io。IoException:错误的AVA格式
- GCM与PHP(谷歌云消息传递)
- 自定义圆圈按钮
- 我如何使用一个复合绘图而不是一个线性布局,包含一个ImageView和一个TextView
- 如何绘制一个线性布局的边界
- 如何动画添加或删除Android列表视图行
- 如何解决“丢失的PendingIntent可变性标志”在android api 30+ lint警告?
- 我怎么能修复“意外元素<查询>发现<manifest>”错误?
- Android房间-自动生成新插入行的id
- Android Studio在哪里保存ProGuard映射文件?
- 我如何从资产文件夹解析一个本地JSON文件到一个ListView?