为了账号安全,请及时绑定邮箱和手机立即绑定

Listview不能显示

Listview不能显示

qq_我很丑绝缘体_0 2016-07-20 10:18:58
public class MainActivity extends Activity { String[] object = { "刘备", "关羽", "张飞", "赵云", "马超", "诸葛亮" }; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); ListView listView = (ListView) findViewById(R.id.listview1); ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(this, R.layout.item, object); listView.setAdapter(arrayAdapter); } }mainactivity布局如下:<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"     xmlns:tools="http://schemas.android.com/tools"     android:layout_width="match_parent"     android:layout_height="match_parent"     android:paddingTop="@dimen/activity_vertical_margin"     tools:context=".MainActivity" >     <ListView         android:id="@+id/listview1"         android:layout_width="match_parent"         android:layout_height="match_parent" >     </ListView> </RelativeLayout>item布局如下:<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"     android:layout_width="match_parent"     android:layout_height="wrap_content"     android:orientation="vertical" >     <TextView         android:layout_width="match_parent"         android:layout_height="wrap_content"         android:text="哈哈"         android:textSize="25sp" /> </LinearLayout>一运行就会报错,报出错误内容为:java.lang.ClassCastException: android.widget.LinearLayout cannot be cast to android.widget.TextView刚学Android求大神指教,这是怎么回事。。?
查看完整描述

2 回答

?
蜂之谷

TA贡献564条经验 获得超863个赞

R.layout.item  改成  android.R.layout.simple_list_item_1

查看完整回答
2 反对 回复 2016-07-20
?
萧一郎

TA贡献20条经验 获得超1个赞

报的类转化异常,LinearLayout不能转化为TextView。 

查看完整回答
反对 回复 2016-07-21
  • 2 回答
  • 0 关注
  • 1139 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信