开发者

Missing R.java file even though project cleaned

Every time in code that I have an R, I get an error R cannot be resolved to a开发者_StackOverflow中文版 variable.

The R.java file appears to be missing.

I have tried cleaning the project.


This can happen when you have an error in one of your xml files (for example, a resource cannot be found). This can also happen because of using menus (I have had this problem because of menus, and I had to remove them, clean and add them again). And another possible reason is that you initially wanted to have your R class not in the default place where it is created but in your own package. So it is possible that R is created in its default location and your program is looking for it somewhere else.


Check your XML resources (especially these recently edited) for mistakes and sytax errors. When you have an error inside one of these files, the R class autogeneration will abort.


Ah, the "R cannot be resolved" error. I think every Android programmer has run across this sometime or the other. I wish the tools were more robust about generation of R.java & class.

Try this, it has worked for me in past:

Right-click on the Project root --> Android Tools --> Fix Project Properties


This happened to me because of a bad resource name (some audio file had " - " in a name), I fixed it by renaming the file.


Check if you accidentally imported android.R, this gives an error with resources as well.


That happens when the project cannot be build, because the project name may not be sufficient for building.

You need to create another project without any unacceptable symbols and copy all code files (.java, xml files, etc) and paste it to newly created project. Then clear your project (project -> clean) and select the build automatically option.


This happened in my case as a image that was present in res/drawable-hdpi had a capital character, I made it small then it worked.


You should definitely check your XML files as most people here post. This is because this problem is most likely because of something in your resources not being right, possibly due to debugging. HOWEVER, if this is not the case you may want to check for folders with any resources that have any CAPITAL LETTERS. also you want to make sure you are using the roman alphabet to name resources properly. This made me scratch my head a little bit because a lot of my folders and settings are in Chinese. I saved some projects to a workspace in a folder in Dropbox named 麥思樂的安卓計劃. I changed the name of the folder and problem solved.


Had the same problem but cleaning the project didn't solve anything even with correct xml. This is what I did

a) Make sure the java builders are checked as in the pic below. If they are , uncheck and check again

b) Insert a dummy value eg in layout add a button

c) Clean project

Missing R.java file even though project cleaned


I found solution:

Check is there any <string> </string> is that you forgot to define in string.xml while copying file from outside.


This is a very common issue, this is encountered when we edit any of the xml file in our project like drawable, layout, strings etc.

We usually clean project (or) restart our IDE (or) import R.java when we get this problem. Never do import.

First try to fix the errors in all xml files and then remove the R.java import from java files. And then clean the project.

So simple.


If you do not see R.java file generation upon creating an Android project, then you probably have missed downloading Android SDK Tools in the Android SDK Manager. In eclipse, go to Window-->select Android SDK Manager Once the Android SDKManager window opens, check the Tools folder and install. Once the installation is completed, restart the eclipse IDE. Build your project and you can see the R.java file generated under the gen folder of your Android project.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜