Android Studio中的“无法解析符号R”

本文翻译自:“cannot resolve symbol R” in Android Studio

Want to improve this post? 想要改善这篇文章吗? Provide detailed answers to this question, including citations and an explanation of why your answer is correct. 提供此问题的详细答案,包括引文和为什么答案正确的解释。 Answers without enough detail may be edited or deleted. 答案不够详细的答案可能会被编辑或删除。

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". 在我引用R.id.something所有类的所有实例中, R均为红色,并显示“无法解析符号R”。 Also every time there is R.layout.something it is underlined in red and says "cannot resolve method setContentView(?)". 同样,每次有R.layout.something它都会用红色下划线表示“无法解析方法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. 我在这里阅读了许多其他问题,这些问题与相似但最涉及从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. 我使用的是我认为是Android Studio的最新版本,并且该项目是使用Android Studio创建的,并且可以正常工作而没有任何“无法解决R”问题。 I would like to know what causes this if anyone knows. 如果有人知道,我想知道是什么原因造成的。


#1楼

参考:https://stackoom.com/question/19YWW/Android-Studio中的-无法解析符号R


#2楼

Have you updated your SDK tools recently? 您最近是否更新了SDK工具? Launch the android SDK manager and make sure you have the latest SDK tools, which is now separate from the platform tools. 启动android SDK Manager,并确保您拥有最新的SDK工具,该工具现已与平台工具分开。 I had this same issue when I first updated my SDK manager, the SDK build tools package did not show up for install/update until I closed and reopened the SDK manager. 我有同样的问题,当我第一次更新我的SDK管理器,该SDK 构建工具包没有露面的安装/升级,直到我关闭并重新打开SDK管理器。


#3楼

I had the same problem, and it happens when I create a new project. 我遇到了同样的问题,当我创建一个新项目时就会发生。

What I do is: 我要做的是:

  • check for SDK updates 检查SDK更新
  • then android studio updates, 然后android studio更新,
  • then reopen the project 然后重新打开项目
  • open the andoridmanifest.xml 打开andoridmanifest.xml
  • erase a space between a "_>" in the android:label and save. 删除android:label中“ _>”之间的空格并保存。

That works for me. 这对我行得通。


#4楼

This notation seems to work fine. 这种表示法似乎工作正常。

android:id="@+id/viewID"

Android Studio's design panel doesn't seem to work well. Android Studio的设计面板似乎无法正常运行。


#5楼

I had this this issue too. 我也有这个问题。 A simple 'gradlew clean' and 'gradlew build' did the trick. 一个简单的“ gradlew clean”和“ gradlew build”就可以解决问题。


Click on Build->Clean Project and that will perform a gradle clean 点击Build- > Clean Project ,这将执行gradle clean


#6楼

I have had this with 我有这个

  1. An uppercase letter in my drawable resources. 我的可绘制资源中的一个大写字母。
  2. Import Android.R being added by Android Studio (or Eclipse) 导入由Android Studio(或Eclipse)添加的Android.R
  3. Error in xml file xml文件中的错误

你可能感兴趣的:(android,android-studio,r.java-file)