Android TextView 转换错误:android.widget.LinearLayout 无法转换为 android.widget.TextView
我的布局文件中有以下文本视图,这是布局文件的完整内容:
<?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"
/>
它已经在我的应用程序中使用了一年左右,没有任何问题。突然间我收到错误: android.widget.LinearLayout 无法转换为 android.widget.TextView
我无法弄清楚。
布局文件中充满了这样的代码:
TextView seasonTv = (TextView)mInflater.inflate(R.layout.section_title, null);
任何关于为什么会发生这种情况的见解吗?
谢谢!
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 layout 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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您似乎正在传入 null 作为视图组的根元素。我假设充气器将您的视图组默认为线性布局,而您实际上根本没有视图组。我会尝试修改您的 inflate 调用,因为您的布局文件显示正常。
来源: http://developer.android.com/reference/android/view/LayoutInflater .html
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
尝试这个
您尝试膨胀布局并将其投射到 TextView 小部件。
您应该膨胀布局并找到小部件
try this
You trying to inflate layout and cast it to TextView widget.
You should inflate layout and find widget