运行闪退怎么解决
public class MainActivity extends AppCompatActivity {
private GridView gridView;
private SimpleAdapter adapter;
private List<Map<String,Object>> dataList;
private int[] icon={R.drawable.test,R.drawable.clipboard1,R.drawable.test11,R.drawable.test12};
private String[]iconName={"设置","天气","相机","阳光"};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
gridView=(GridView) findViewById(R.id.gridView);
dataList=new ArrayList<Map<String,Object>>();
adapter=new SimpleAdapter(this,getData(),R.layout.item,new String[]{"image","text"},new int[]{R.id.image1,R.id.text1});
gridView.setAdapter(adapter);
}
private List<Map<String,Object>> getData(){
for(int i=0;i<icon.length;i++){
Map<String,Object>map=new HashMap<String,Object>();
map.put("image1",icon[i]);
map.put("text1",iconName[i]);
dataList.add(map);
}
return dataList;
}
}
报错: Attempt to invoke virtual method 'void android.widget.GridView.setAdapter(android.widget.ListAdapter)' on a null object reference