Android See recruit recruit Eight: R.java compilation problems encountered many times

Source: Internet
Author: User

Problem description

R cannot is resolved to a variable

Cause of the problem

The naming specification when defining an ID causes compilation errors, cannot use numbers, must use the English alphabet

Remember not to do it again.

In addition, there may be other reasons why R cannot is resolved to a variable, many times R.java not generated due to various reasons, the troubleshooting method is as follows

Reprinted from http://blog.csdn.net/jason0539/article/details/9708025

1. Check if the Android SDK is missing and need to download again, check the build path, import the jar package confirmation to the successful
2. Ensure that class does not have import ANDROID.R, note that there is no ANDROID.R, there can be other R files, such as your own package;
3. Error class refers to the layout of the XML file is not an error, often there is an error in the XML, causing the R file does not build properly

Most of the time this place is wrong, you can try to add a control in the layout of the XML file, to see if the ID can be automatically generated in the R.java, if not, it is very likely that the layout of the XML file has a problem, to see whether the format is used correctly, or contain what illegal string, or call to an incorrect string, and so on, you can use the exclusion method to remove the control, until you find that the error message disappears or the ID can be automatically generated in R.java. Remember that often because of the Android word misspelled and the R file does not generate normally and always r cannot be resolved to a variable


4. Check the Androidmanifest.xml file, inside the package,layout configuration file, Strings.xml and other strings are all written correctly.

5. Delete the Gen folder, make the R.java auto-generated once, if not, continue to check the layout of the XML file is not easy to find the problem
6.Clean project, re-build, or re-import project.
7. Restart Eclipse
8. Restart your computer to prevent problems with your Android virtual machine

Reprinted from Http://blog.sina.com.cn/s/blog_8a94d82b0101bdfb.html

It's strange that when importing a project for the first time, it didn't produce the R.java file, and a lot of errors in the program were all r cannot be resolved to a variable.

Results on the Internet search for half a day, the result is

The first method to find out:

Many people encounter the problem of cannot be resolved to a variable when they create a new project, they can't get the best solution in the first time.

The root cause is that the R.java file is not automatically generated

About the general solution on the Internet a lot of people have come up with this

such as clean engineering, clean up resource,android Tools >> Fix project Properties, etc.

But still some people see the online post still can't solve, then please note two points:

1. If you are updating the SDK, then shut down and restart Eclipse to

2. If not, update the full ADT, SDK

This article is from the "Breeze Willow" blog, please be sure to keep this source http://binuu.blog.51cto.com/801317/775781

The second method to find out:

*note:eclipse sometimes likes to add a "import Android. R "statement at the top of the your files that use resources, especially if you ask for Eclipse to sort or otherwise manage impo Rts. This would cause Your  make  to break. Look out for these erroneous import statements and delete them.*

While going through the Android sample tutorials, I would often use the Ctrl + Shift + O comm And to ' Organize Imports ' and generate any missing import statements. Sometimes this would generate the incorrect import statement which would hide the class that's R.java Automatica Lly generated when you build.

Self-perception should be the process of generating r.java is interrupted or an accident occurred, so delete the original project, re-import,

Oh oh, this time it really is! The R.java file is automatically generated.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.