Android空指针异常问题,新手求教

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

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.stu.bean.Student;
import com.stu.service.StudentService;

import android.app.Activity;
import android.os.Bundle;
import android.widget.ListView;
import android.widget.SimpleAdapter;

public class MainActivity extends Activity {
private StudentService studentService=null;
private ListView listView=null;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
studentService=new StudentService(getApplicationContext());

listView=(ListView)findViewById(R.id.listView);

show();
}

private void show() {
List<Student> students=studentService.getScrollData(0,20);

List<Map<String,Object>> data=new ArrayList<Map<String,Object>>();

for(Student student:students)
{
Map<String,Object> map=new HashMap<String, Object>();
map.put("name",student.getName());
map.put("age",student.getAge());
map.put("money",student.getMoney());
map.put("id",student.getId());
data.add(map);
}

//创建SimpleAdapter对象
SimpleAdapter adapter=new SimpleAdapter(getApplicationContext(), data,R.layout.item,
new String[]{"name","age","money"},new int[]{R.id.name,R.id.age,R.id.money});

listView.setAdapter(adapter);//这个地方提示空指针异常

}
}



...全文

相关推荐

评论 8
收藏 已收藏
分享
返回顶部
IT_163
Android 80,490 成员 91,375 内容