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

来源:互联网 发布:中国地理拼图软件 编辑:程序博客网 时间:2024/05/16 07:00

报出异常的原因是由于少添加了个一个构造方法,参数为(Context, AttributeSet),其中第二个参数用来将xml文件中的属性初始化。

自定义控件若需要在xml文件中使用,就必须重写带如上两个参数的构造方法。添加后即可正常使用了。

[java] view plaincopyprint?在CODE上查看代码片派生到我的代码片
  1. public TestButton(Context context, AttributeSet attributeSet) {  
  2.     super(context, attributeSet);  
  3.     // TODO Auto-generated constructor stub  
  4. }  

0 0
原创粉丝点击