可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
I am having a problem with the gen/r.java file. When I create or edit files in resources such as layout /values/strings.xml e.t.c the r.java file does not update. I have followed a tutorial and it for some reason won't update. There are no errors in the xml file.
I have heard people say "use clean/build" e.t.c but this just removes the r.java file and I am unable to get it back after many attempts. This results in me having to redo the whole project again just to get the gen file back. Why is this happening?
回答1:
Project -> Clean works for me.
R.java is deleted & Auto generated.
回答2:
I ran into this before, I work around we discovered was that the R.java file only gets generated after an edit to the Mainfest.xml file. So just make a quick change to that file.
回答3:
this will work for you.....
Go project > clean . it will generate your R.java or you can delete your R.java and Eclipse will automatically generate your R.java.
回答4:
There is a good possibility this is because you are not abiding by appropriate naming conventions in your res folder. I had this same issue and - using intellij IDE - right clicked on the res file and hit 'Force regenerate R'. Intellij told me:
Invalid file name: must contain only [a-z0-9]
So, in addition to what others have said here, check your naming conventions and make sure you haven't included any caps, underscores, dashes, etc. in the files you put into your res folder.
回答5:
I face same problem during myproject. Make sure that there is no error in any of the xml file. If one of the xml that contain error R.java file does not update.
回答6:
You should check your Manifest file for correct path for the packages. Generally when do changes we forget about the class path for the MainActivity or we rename the main class or package. Then remove the R file and do the Project -> Clean , to regenerate R file. Hope this helps.
回答7:
I had same problem, and when I check tab Console
, there red line that explain me there a wrong name file at picture in drawable folder. After rename it, everything working fine.
回答8:
The problem could be that you have 'import android.R' at the head of the file or near it. If it is the case, remove the line and try again.
回答9:
Check if ID foreach UI is like
android:id="@android:id/tabs"
I had the same problem, and changing in this way:
android:id="@+id/tabs"
Solved the problem!
回答10:
I have had this problem before, here are some ways to fix it
1. make sure in the Manifest.xml that the package is set to the right name.
2. make sure your gen matches your package name example
gen/com.expample.pack/R.java
Also I have found if you edit it in eclipse it will regenerate.
回答11:
THE MASTER HAS ALWAYS A SOLUTION. (All solutions are not the good)
Experience is better than all
If your problem is that the "gen/ R.java" isn't updating the new ID,DRAWABLE or Strings that you declared, it's simply because there's a fatal error in one or some of your XML pages.
1 : the most of times it's with the res/values/string.xml file , so go in the file, click "XML View" at the right of "ressources" then you will for sure notice a red-mark at the right or the left of your XML page.
- focus on it :
- you can read something like "error: apostrophe not preceded by \ (...)".
That means in your text, there is one or more apostrophes. the solution is to preceed all the apostrophes with \ back-slash. -
- You can fix all the apostrophes pressing : CTRL+F and insert an apostrophe(') at the first box then a \' at the second. then click the "Replace all" button at the bottom of the dialog.
2 : give me your error, and i'll answer you in less than 1h
回答12:
I got this error while I used camel naming conventions in files under the res folder of my application.
I have corrected them and cleaned my project, it resolved my issue.