Caused by: android. view. InflateException: Binary XML file line #11: Error inflating class

Source: Internet
Author: User

An exception occurs when the default Android Button is rewritten:

Caused by: android. view. InflateException: Binary XML file line #11: Error inflating class com. example. activity1.TestButton

The code for the custom control is as follows, but the onTouchEvent method is simply rewritten and cannot be used normally.

Public class TestButton extends Button {public TestButton (Context context) {super (context); // TODO Auto-generated constructor stub} @ Overridepublic boolean onTouchEvent (MotionEvent event) {boolean value = super. onTouchEvent (event); System. out. println ("super. onTouchEvent: "+ value); return value ;}}

The error is reported because a constructor is added with the (Context, AttributeSet) parameter. The second parameter is used to initialize the attributes in the xml file.

To use a custom control in an xml file, you must override the constructor with the preceding two parameters. After being added, it can be used normally.

Public TestButton (Context context, AttributeSet attributeSet) {super (context, attributeSet); // TODO Auto-generated constructor stub}



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.