Android R.java problems. R.java file does not upda

2020-03-01 07:31发布

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?

12条回答
兄弟一词,经得起流年.
2楼-- · 2020-03-01 07:48

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.

查看更多
何必那么认真
3楼-- · 2020-03-01 07:49

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楼-- · 2020-03-01 07:51

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!

查看更多
Summer. ? 凉城
5楼-- · 2020-03-01 07:57

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.

查看更多
Ridiculous、
6楼-- · 2020-03-01 07:59

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.

查看更多
迷人小祖宗
7楼-- · 2020-03-01 08:02

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.

查看更多
登录 后发表回答