简体   繁体   English

Android 工作室错误 R.java

[英]Android studio error R.java

I have an error in the R.java file when I open android studio 3.0.当我打开 android studio 3.0 时,我在 R.java 文件中有一个错误。

Here is the error:这是错误:

这是错误

public static final int Both are incorrect=0x7f080002;

when I try to edit it or delete this line it keeps saying that:当我尝试编辑它或删除这一行时,它一直说:

"Generated source files should not be edited, The changes will be lost when the sources are regenerated" “不应编辑生成的源文件,重新生成源时更改将丢失”

This error mostly occurs due to the change in your layout.xml file此错误主要是由于您的layout.xml文件中的更改而发生的

try to check your id's in layout.xml file as尝试在 layout.xml 文件中检查您的 ID

  • id's should not contain spaces id 不应包含空格
  • id's should not start always with numbers id 不应该总是以数字开头
  • id's should not be repeated id 不应该重复
  • id's should start with @+ or + id 应该以 @+ 或 + 开头

try to clean your project from menu or sync with gradle files.尝试从菜单中清理您的项目或与 gradle 文件同步。

The error happens because you have a wrong id in your layout.发生错误是因为您的布局中有错误的id You can't use a space for id name in a view.您不能在视图中为 id 名称使用空格。

You need to check for the following id in your layout:您需要在布局中检查以下 ID:

android:id="@+id/Both are incorrect"

Then remove or change the space, you can use underscore:然后删除或更改空格,可以使用下划线:

android:id="@+id/both_are_incorrect"

You can't edit R.java file because this file is auto-generated by compiler.您无法编辑 R.java 文件,因为该文件是由编译器自动生成的。 And your problem is you can never use space in "id" & variable as well so first change your ID (it's better if you rename id using refactor) and rebuild you project hopefully it will work... Happy coding... :)你的问题是你永远不能在“id”和变量中使用空格,所以首先更改你的 ID(如果你使用重构重命名 id 会更好)并重建你的项目,希望它会起作用......快乐编码...... :)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM