Why Android can't generate R files

Source: Internet
Author: User
Tags constant

It is painful that Android cannot generate r files, even if there are times when you have no errors in the XML file. To solve this problem, I summarize the following reasons.

One. XML itself has errors

R.java This file is automatically generated, but if you accidentally write the XML file incorrectly, or accidentally click Run when editing XML (in fact, this time will run this XML file, will generate an XML file with the same name, suffix of xx.out.xml), and then happened to you swim Clear the project, you may find that Gen below the R.java file is not, this is very irritating at the beginning, really do not know how to solve, and later found that, as long as the XML file has problems, the system is absolutely will not give you automatically generate this R.java file, because he has to refer to your every Data in the XML to generate R.java, so naturally it can't be generated. Although know the reason but the problem headache, if the project's layout XML file has dozens of, this time how to do, do you want an XML to see it, hehe, in fact, is not, the information in the console clear, and then clear the project, this time, The console will have a lot of red information, referring to this will certainly be able to accurately find which file error.

The following is a mistake to run the XML file, you can see that Gen's package is not empty, R.java file also exists, and the explicit expenditure is layout package in the error

Two. Incorrect encoding format

Sometimes because of coding format problems, resulting in the inability to generate R file, at this time, the encoding format into Utf-8 can

Third, for unknown reasons, it may be a configuration problem (an escape character problem).

In general, the Android project R file is defined by the system-generated resources, but occasionally the R file is not synchronized or missing.

The situation is not synchronized, that is, there is already an item in the Res file, but it is not defined in the R.java file.

Here you can click, Project->clean, select the item, and then select "Start a build immediately" to rebuild the R file.

If r files are missing, the recommended method for general online is to right-click the project file and click on "Android Tools"-> "Fix Project Properties".

But sometimes this method is not available, so it's time to re-examine whether the XML resource file in the Res folder is using the escape character.

Using I define a string constant named "str" in string, if you use an escape (illegal) character in a constant value, compile

There will be a case of R file loss.

Commonly used to the need to escape the characters have:<>& "' etc, interested can refer to the article on the Internet, the following given the commonly used escape encoding:

Escape character Actual symbol name

&lt; < less than number

&gt; > Greater than number

&amp; & and

&apos; ' Single quotes

&quot; "Double quotes

Note the semicolon after the escape character (;) not be omitted!)

This is the case where I summed up the inability to generate the R file.

See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/OS/extra/

Related Article

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.