android写的一个自定义listView出现空指针异常但是找不到哪里错。。

superboboge superboboge 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
package com.bobo;
import java.util.ArrayList;
import java.util.HashMap;
import android.app.Activity;
import android.os.Bundle;
import android.widget.ListView;
import android.widget.SimpleAdapter;

public class ItemActivity extends Activity {
private ListView listView;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
listView = (ListView)findViewById(R.id.chat1);
ArrayList<HashMap<String, Object>> listItem = new ArrayList<HashMap<String,Object>>();
// for (int i = 0; i < 5; i++) {
HashMap<String, Object> map = new HashMap<String, Object>();
map.put("name", "name");
map.put("time", "time" );
map.put("message", "message");
listItem.add(map);
// }
SimpleAdapter simpleAdapter = new SimpleAdapter(this,listItem,
R.layout.chat_item,
new String[]{"name","time","message" },
new int[]{R.id.show_name,R.id.show_time,R.id.message}
);
listView.setAdapter(simpleAdapter);
}
}

以上是activity的代码


下面是listview的chat.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:id="@+id/LinearLayout01"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<ListView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/chat1"
/>
</LinearLayout>

然后是自定义布局chat_item.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:padding="6dip" >

<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content">

<TextView android:id="@+id/show_name"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="asassa"

/>

<TextView android:id="@+id/show_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0"
android:text="asassa"
/>

</LinearLayout>
<TextView android:id="@+id/message"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="asassa"
/>

</LinearLayout>

不知道哪里错了大神求帮助
...全文
评论 11
收藏 已收藏
分享
返回顶部
superboboge
Android 80,490 成员 91,371 内容