package listview.Package; import java.util.HashMap; import java.util.List; import java.util.Map; import android.app.Activity; import android.os.Bundle; //import android.widget.ArrayAdapter; import android.widget.ListView; import android.widget.SimpleAdapter; public class ListviewActivity extends Activity { private ListView list; // private ArrayAdapter<String> arrayadapter; private SimpleAdapter simpleAdapter; //String[]data={"慕课网1","慕课网2","慕课网3"}; private List<Map<String, Object>> datalist; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.listviwe); list=(ListView) findViewById(R.id.listView1); //arrayadapter=new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,data); list.setAdapter(simpleAdapter); simpleAdapter=new SimpleAdapter(this,getdata(),R.layout.itme, new String[]{"img","text"}, new int[]{R.id.imageView1,R.id.textView1}); } private List<Map<String, Object>> getdata(){ for(int i=0;i<10;i++){ Map<String, Object> map =new HashMap<String, Object>(); map.put("img", R.drawable.ic_launcher); map.put("text", "慕课网"+i); datalist.add(map);} return datalist; } }
运行到模拟器,程序立马就停,logcat打印说是空指针异常,请问哪里错了,怎样改正。。!?
小寳_昭乂阳
t80000
一步一个脚印_梦想
qq_倚天_0
相关分类