[英]Cannot resolve symbol R. [Tried all the solutions mentioned]
I am making an Android app.我正在制作一个Android应用程序。 Due to some reasons, my current project files got all messed up.
由于某些原因,我当前的项目文件都搞砸了。 To solve this issue I created a new project in Android Studio and copied the files from the previous project to this new project.
为了解决这个问题,我在 Android Studio 中创建了一个新项目,并将之前项目中的文件复制到这个新项目中。
I carefully copied all the layout, values, java files at their right location.我小心地将所有布局、值、java文件复制到了正确的位置。 I replaced the relavant content from the new manifest and gradle files with new content.
我用新内容替换了新清单和 gradle 文件中的相关内容。
Everything looked perfect and then I got the "Cannot resolve symbol R" error.一切看起来都很完美,然后我收到了“无法解析符号 R”的错误消息。
I tried all the solutions like Invalidate Cache/Restart, Sync files with gradle, Rebuild Project, Clean Project etc. etc. etc.我尝试了所有解决方案,例如无效缓存/重启、使用 gradle 同步文件、重建项目、清理项目等等等。
Still couldn't fix it.还是没能修好。
Can someone help?有人可以帮忙吗?
Problem Details 1. I have correct package name everywhere (in AndroidManifest too) 2. I have proper and valid xml files 3. Even if I copied the files from other project the I've kept the project name and package names exactly the same.问题详细信息 1. 我到处都有正确的包名(在 AndroidManifest 中也是) 2. 我有正确有效的 xml 文件 3. 即使我从其他项目复制了文件,我也保持项目名称和包名称完全相同。 4. I have only one app module.
4. 我只有一个应用模块。
尝试从每个 java 类中删除 .R 行。
You might have an error in one of your xml
files, like a duplicated xml
header.您的
xml
文件之一可能有错误,例如重复的xml
标头。 Check for every single one.检查每一个。
You can also update Android Studio as it now tells you the file and location of the error.您还可以更新 Android Studio,因为它现在会告诉您错误的文件和位置。
I strongly suggest you copy and paste your codes to individual right places if you want to move these to a new project.如果您想将这些代码移动到新项目,我强烈建议您将代码复制并粘贴到各个正确的位置。 Copying folders and files to a newly created project would not work as there could be some lines that include your old folder paths
将文件夹和文件复制到新创建的项目将不起作用,因为可能有一些行包含您的旧文件夹路径
For example, your old project was in C://StudioProjects/YourProjectName
so your codes should be in C://StudioProjects/YourProjectName/app/src/main/java/com/example/AppName
but if you directly copy a file or folder to a newly created project, you could end up referencing the wrong path like C://StudioProjects/YourProjectName/app/src/main/java/com/example/NewAppName
and this could blow your XML file which will lead to R cannot resolve symbol R.例如,您的旧项目位于
C://StudioProjects/YourProjectName
因此您的代码应位于C://StudioProjects/YourProjectName/app/src/main/java/com/example/AppName
但如果您直接复制文件或文件夹到一个新创建的项目,你最终可能会引用错误的路径,比如C://StudioProjects/YourProjectName/app/src/main/java/com/example/NewAppName
这可能会C://StudioProjects/YourProjectName/app/src/main/java/com/example/NewAppName
你的 XML 文件,这将导致 R 不能解析符号 R。
Even though you put your folders in the same path, reference numbers changed in the new project.即使您将文件夹放在同一路径中,新项目中的参考编号也发生了变化。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.