{"id":2221,"date":"2022-08-30T15:23:03","date_gmt":"2022-08-30T15:23:03","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/01\/05\/inflating-custom-view-causes-error-collection-of-common-programming-errors\/"},"modified":"2022-08-30T15:23:03","modified_gmt":"2022-08-30T15:23:03","slug":"inflating-custom-view-causes-error-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/inflating-custom-view-causes-error-collection-of-common-programming-errors\/","title":{"rendered":"Inflating custom view causes error-Collection of common programming errors"},"content":{"rendered":"<p>I have created a custom view that includes an ImageButton and a TextView. This is my layout:<\/p>\n<pre><code>\n\n     \n\n         \n\n<\/code><\/pre>\n<p>I also have a class that inherits from RelativeLayout called CustomImageButton. This is part of it&#8217;s code:<\/p>\n<pre><code>public class CustomImageButton extends RelativeLayout {\n\n    ...\n\n    public CustomImageButton(Context context, AttributeSet attrs) {\n        super(context, attrs);\n        this.attributes = context.obtainStyledAttributes(attrs, R.styleable.CustomImageButton);\n    }\n\n    @Override\n    protected void onFinishInflate() {\n        super.onFinishInflate();\n\n        ((Activity)getContext()).getLayoutInflater().inflate(R.layout.custom_image_button, this);\n        this.setClickable(false);\n        setupViewItems();\n    }\n\n    private void setupViewItems() {\n          \/\/ DO STUFF HERE TO THE IMAGE BUTTON AND TEXT VIEW\n          \/\/ FROM THE CUSTOM ATTRIBUTES \n    }\n}\n<\/code><\/pre>\n<p>These are the custom attribute given to the Custom image button: (attrs.xml)<\/p>\n<pre><code>\n\n    \n        \n        \n        \n        \n        \n            \n            \n            \n        \n        \n    \n\n<\/code><\/pre>\n<p>and finally this is the main layout:<\/p>\n<pre><code>\n\n\n    \n\n    \n\n        \n\n        \n\n\n<\/code><\/pre>\n<p>and now, for the problem. When i run my application on android 4.0.2 and higher everything is ok BUT, when i run my app on android 2.2.1 i get<\/p>\n<pre><code>android.view.InflateException: Binary XML file line #5: Error inflating class \n<\/code><\/pre>\n<p>according to the stack trace (which is VERY uninformative) the exception is thrown from the <code>CustomImageButton<\/code> class in the <code>onFinishInflate<\/code> method when i call the <code>inflate<\/code> method. Any ideas why and how can i fix this?<\/p>\n<p id=\"rop\"><small>Originally posted 2014-01-05 09:04:26. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>I have created a custom view that includes an ImageButton and a TextView. This is my layout: I also have a class that inherits from RelativeLayout called CustomImageButton. This is part of it&#8217;s code: public class CustomImageButton extends RelativeLayout { &#8230; public CustomImageButton(Context context, AttributeSet attrs) { super(context, attrs); this.attributes = context.obtainStyledAttributes(attrs, R.styleable.CustomImageButton); } @Override [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-2221","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/2221","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=2221"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/2221\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=2221"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=2221"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=2221"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}