开发者

Android TextView casting error: android.widget.LinearLayout cannot be cast to android.widget.TextView

I have the following textview in a layout file, this is the full contents of the layout file:

<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/seasonTitle"
    android:padding="3dip"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:textColor="#FFFFFFFF"
    android:textSize="14sp"
    android:textStyle="bold"
    android:maxHeight="26sp"
    android:background="#FFCC3333"
     />

It has been in my app for a year or so with no problems. All of the sudden I'm getting the error: android.widget.LinearLayout cannot be cast to android.widget.TextView

I can't figure it out.

The layou开发者_运维问答t file is inflated with code like this:

TextView seasonTv = (TextView)mInflater.inflate(R.layout.section_title, null);

Any insight on why this is happening?

Thanks!


It appears that you are passing in null as the root element of the view group. I would assume that the inflater is defaulting your view group to a linear layout, when you don't actually have a view group at all. I would try to modify your inflate call, as your layout file appears OK.

source: http://developer.android.com/reference/android/view/LayoutInflater.html


try this

View season = (View)mInflater.inflate(R.layout.section_title, null);
TextView seasonTv =  (TextView)findViewById(R.id.seasonTitle);

You trying to inflate layout and cast it to TextView widget. You should inflate layout and find widget

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜