声明一个对象数组
HashMap[]map1 = new HashMap[10];
for(int i = 0;i<10;i++){
map1[i].put("touxiang", R.drawable.touxiang);
map1[i].put("nicheng", "荒城旧日");
map1[i].put("content", "fweggwgwgwf"
+" gwgw");
map1[i].put("img", R.drawable.dongtai);
}
以上代码会报空指针异常
应该为每一项申请一个空间,应该改为
HashMap[]map1 = new HashMap[10];
for(int i = 0;i<10;i++){
map1[i] = new HashMap();
map1[i].put("touxiang", R.drawable.touxiang);
map1[i].put("nicheng", "荒城旧日");
map1[i].put("content", "fweggwgwgwf"
+" gwgw");
map1[i].put("img", R.drawable.dongtai);
}