无法运行,请问哪里出错了?
package com.ash.gridview; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.widget.GridView; import android.widget.SimpleAdapter; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; public class MainActivity extends AppCompatActivity { private GridView gridView; private List<Map<String, Object>> dataList; private int[] icon = {R.drawable.on2, R.drawable.on2, R.drawable.on2 , R.drawable.on2, R.drawable.on2, R.drawable.on2, R.drawable.on2, R.drawable.on2,}; private String[] iconName = {"1", "2", "3", "4", "5", "6", "7", "8"}; private SimpleAdapter adapter; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // setContentView(R.layout.activity_main); setContentView(R.layout.main); getData(); gridView = (GridView) findViewById(R.id.gridview); dataList = new ArrayList<Map<String, Object>>(); adapter = new SimpleAdapter(this, getData(), R.layout.tem, new String[]{"image", "text"} , new int[]{R.id.image, R.id.text}); gridView.setAdapter(adapter); } private List<Map<String, Object>> getData() { Map<String, Object> map = new HashMap<String, Object>(); for (int i = 0; i < icon.length; i++) { map.put("image", icon[i]); map.put("text", iconName[i]); dataList.add(map); } return dataList; } }
build.gradle
defaultConfig { applicationId "com.ash.gridview" minSdkVersion 16 targetSdkVersion 23 versionCode 1 versionName "1.0" }
运行手机 API 16 ,请问哪里出问题了?