开发者

In Eclipse, when building an Android app I've somehow deleted the "R" class and cannot get Eclipse to generate it again

开发者 https://www.devze.com 2023-01-02 20:12 出处:网络
I\'m new to Eclipse/Android development so I\'m hoping this is something basic that I\'m just doing wrong.Basically I\'ve been playing around with developing Android apps and I was editing one earlier

I'm new to Eclipse/Android development so I'm hoping this is something basic that I'm just doing wrong. Basically I've been playing around with developing Android apps and I was editing one earlier. I changed my main.xml file and when I went back to my class that runs the app all references to the "R" class were broken. I looked in the "gen" folder (Generated Java Files) and saw that the class was completely gone from the solution.

I had been debugging not 5 minutes before and didn't have any problems doing so. The only things I had done since debugging were moving 2 files from the "draw开发者_Python百科able-hdpi" folder to the assets folder and I had edited the "main.xml" file.

I've tried cleaning the project and restarting Eclipse but neither of those ideas worked. Any suggestions?


Check your main.xml file. If there is a fault in it (invalid XML, wrong element name, etc), then the R.java file may not be generated properly and you will have broken references.

Also make sure that the XML file itself does not have broken references (to strings, colors, and other kinds of assets).

Re-examine properly all that has changed since the last time your application was working.


I have been in your situation before. I dont have direct answer. I assume you still learning Android (Like me) ...

The best thing is redo or rewrite the code from the beginning. It sharpen your skill, and sometimes in the middle you find the answer. It more quicker, Rather than staring the code and try to fix it.

It work for me, but need patient (which sometimes, I dont have it ...) ;)


I have had this problem also.

By typing an error in one of the xml files, R Class couldn't be generated. Eclipse then is so friendly of adding an import to Android.R automagically. This is often overlooked.

Fixing the xml-file errors will regenerate the R class. But your code is not linked anymore to your.own.namespace.R But to Android.R and there it will not find your items.

Removing the Import Android.R from the top of your file fixes this problem.

To be sure if the R class is generated, but wrongly imported, you can look under the folder "gen", there should be R.java file. You could also try by typing your.own.namespace.R. and see if the intellisense shows your items then.

0

精彩评论

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