InflateException: Bin file line #19: Error inflating class MyTextView,

Source: Internet
Author: User

InflateException: Bin file line #19: Error inflating class MyTextView,
InflateException: Bin file line #19: Error inflating class MyTextView

I. Error description

To achieve the effect of TextView, I wrote a class of MyTextView to inherit TextView. The result is an error when calling the XML page of layout.

The class structure is as follows:

The error message is as follows:

The error area code is as follows:

/TextViewDemo1/res/layout/activity04.xml

1 <? Xml version = "1.0" encoding = "UTF-8"?> 2 <LinearLayout xmlns: android = "http://schemas.android.com/apk/res/android" 3 android: layout_width = "match_parent" 4 android: layout_height = "match_parent" 5 android: orientation = "vertical"> 6 <TextView 7 android: id = "@ + id/TV _runHorseLamp" 8 android: layout_width = "match_parent" 9 android: layout_height = "wrap_content" 10 android: singleLine = "true" 11 android: ellipsize = "marquee" 12 android: focusable = "true" 13 Ndroid: focusableInTouchMode = "true" 14 android: text = "this is a long and mighty rolling section that achieves the effect of running the horse lamp. It has a very strong meaning and strong cultivation." 15/> 16 <! -- Ellipsize indicates the decimal point. marquee is used to add a scroll effect --> 17 <! -- Scroll only after obtaining the focus --> 1819 <MyTextView20 android: id = "@ + id/TV _runHorseLamp1" 21 android: layout_width = "match_parent" 22 android: layout_height = "wrap_content" 23 android: ellipsize = "marquee" 24 android: singleLine = "true" 25 android: text = "this is a long and mighty rolling text that achieves the effect of running the horse lamp. It has a very high meaning and strong cultivation." 26/>27 28 29 <EditText30 android: id = "@ + id/et_1" 31 android: layout_width = "match_parent" 32 android: layout_height = "wrap_content" 33> 34 </EditText> 35 36 </LinearLayout>
1 <MyTextView2 android: id = "@ + id/TV _runHorseLamp1" 3 android: layout_width = "match_parent" 4 android: layout_height = "wrap_content" 5 android: ellipsize = "marquee" 6 android: singleLine = "true" 7 android: text = "this is a long and mighty rolling text that achieves the effect of running the horse lamp. It has a very high meaning and strong cultivation." 8/>

Fry. MyTextView

 1 package fry; 2  3 import android.content.Context; 4 import android.util.AttributeSet; 5 import android.widget.TextView; 6  7 public class MyTextView extends TextView{ 8  9     public MyTextView(Context context, AttributeSet attrs, int defStyle) {10         super(context, attrs, defStyle);11         // TODO Auto-generated constructor stub12     }13 14     public MyTextView(Context context, AttributeSet attrs) {15         super(context, attrs);16         // TODO Auto-generated constructor stub17     }18 19     public MyTextView(Context context) {20         super(context);21         // TODO Auto-generated constructor stub22     }23     24     @Override25     public boolean isFocused() {26         // TODO Auto-generated method stub27         return true;28     }29     30 }

 

Ii. Solution

InflateException: Bin file line #19: Error inflating class MyTextView

This statement indicates that the MyTextView class is incorrect,

/TextViewDemo1/res/layout/activity04.xml

1 <MyTextView2 android: id = "@ + id/TV _runHorseLamp1" 3 android: layout_width = "match_parent" 4 android: layout_height = "wrap_content" 5 android: ellipsize = "marquee" 6 android: singleLine = "true" 7 android: text = "this is a long and mighty rolling text that achieves the effect of running the horse lamp. It has a very high meaning and strong cultivation." 8/>

We can see that the class name is used directly, and the referenced class name in XML must contain the package name,

So we changed the first line of the above Code to fry. MyTextView.

The implementation result is as follows:

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.