R.java problems with unrecognized controls

Source: Internet
Author: User

Today in debugging a small online example, encountered a problem: found themselves before the call R.java file r.id.btn ... The retrieved component is suddenly useless, and the following is a red error flag, which is strange. As follows:

Because these components are also called R.java at the time. Can be generated, why is not used now, found in the project in the Gen directory of those automatically generated files R.java and so on, the folder is empty, so by re-cleaning the project, re-build and so did not allow it to produce. Finally, it is solved by the following method,

However, this only solves the problem of auto-generated files without R.java, but does not resolve the generated errors. Then suddenly came a thought: will not be related to the R package did not import or import errors. View the above imported package discovery, there is a related package with R: Import Android. R; The first reaction is that it should be able to use Ah, there are bags ah. Try to delete the next to see what will be reported errors, the result is to make me shocked ..... Even the wrong all disappeared!!! Yes, it's all!!! Wrong, disappeared??!!! Re-add, take a closer look at the notice there is a warning:

Take a closer look at the explanations above to see that it wants us to: don't include Android here. R file, replaced with a fully qualified name each time it is used.

Android. R is the index of the Android resource file, many of which are the default things of the system customization. I tried to import Android. R.id Inner class:

Import Android. r.id; Call the static variable in the ID directly, and enter "ID." The following prompt results are as follows:

These are some of the default constants of the system. Instead of our own defined constants (we passed @+id/in the XML layout file ...). Added in this way). In fact, the location of the constants we define ourselves is the ones that Android automatically generated for us, here: R.java.

Then I went to see the previous project and found that there was no import Android at all. R this sentence. There was no such mistake at that time. This proves that we are importing Android. After the R package, the R.id call is no longer the ID constant of the control that we added ourselves, but the added system custom constants (which is why the system can automatically add a similar android:id= to us when we don't define the ID property for the dragged-in control) @+id/ Button1, and it will grow in burrows, such as: Button2,button3, ... And obviously when we call our own control we will not automatically prompt, and we force the manual input after the error, because the R static class and its following ID static class with our own definition of the same name, unrecognized, resulting in our inability to access our own control.

So the solution is to get rid of the word that sometimes the system automatically imports Android for us. R Package: Import Android. R

R.java problems with unrecognized controls

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.