简体   繁体   中英

Android studio error R.java

I have an error in the R.java file when I open android studio 3.0.

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

try to check your id's in layout.xml file as

  • id's should not contain spaces
  • id's should not start always with numbers
  • id's should not be repeated
  • id's should start with @+ or +

try to clean your project from menu or sync with gradle files.

The error happens because you have a wrong id in your layout. You can't use a space for id name in a view.

You need to check for the following id in your layout:

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. 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... :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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