Duplicate ATTR attributes are defined for multiple classes: Attribute "XXX" has already been defined

Source: Internet
Author: User
If you develop an app independently, you may not encounter duplicate attributes of multiple custom classes. However, if it is developed by a team, you may encounter this problem. The two custom classes A and B use the same name to define attributes. In this case, the system reports a warning, attribute "XXX" has already been defined. A and B don't want to modify their own names. This is a headache.
For example, if you define an above attrs. xml file under the values folder, eclipse will report the error "attribute" icon "has already been defined. In preferenceheader, preference defines two identical attributes.
<? xml version = "1.0" encoding = "utf-8" ?>< resources >     < declare-styleable name= "PreferenceHeader" >        <!-- Identifier value for the header. -->        < attr name= "id" format = "integer"/>        < attr name= "icon" format = "integer" />        <!-- The fragment that is displayed when the user selects this item. -->    </declare-styleable >    < declare-styleable name= "Preference" >        < attr name= "icon" format = "integer" />        <!-- The key to store the Preference value. -->        < attr name= "key" format = "string" />    </declare-styleable ></ resources >

Solution: 1. Declare attributes in the XML file first. 2. Then reference declared attributes in the attribute set. The preceding file is modified as follows:
<? xml version = "1.0" encoding = "utf-8" ?>< resources >     < attr name = "icon" format = "integer" />     < declare-styleable name= "PreferenceHeader" >        <!-- Identifier value for the header. -->        < attr name= "id" format = "integer"/>        < attr name= "icon" />        <!-- The fragment that is displayed when the user selects this item. -->    </declare-styleable >    < declare-styleable name= "Preference" >        < attr name= "icon"  />        <!-- The key to store the Preference value. -->        < attr name= "key" format = "string" />    </declare-styleable ></ resources >



Duplicate ATTR attributes are defined for multiple classes: Attribute "XXX" has already been defined

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.