我想问一下这是什么意思?为什么会报错?
10-05 22:36:46.341 20189-20189/com.mengmengda.gridview E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.mengmengda.gridview, PID: 20189
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.mengmengda.gridview/com.mengmengda.gridview.MainActivity}: java.lang.ArrayIndexOutOfBoundsException: length=10; index=10
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2330)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2392)
at android.app.ActivityThread.access$800(ActivityThread.java:154)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1308)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5273)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:908)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:703)
Caused by: java.lang.ArrayIndexOutOfBoundsException: length=10; index=10
at com.mengmengda.gridview.MainActivity.getData(MainActivity.java:45)
at com.mengmengda.gridview.MainActivity.onCreate(MainActivity.java:36)
at android.app.Activity.performCreate(Activity.java:6041)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1109)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2283)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2392)
at android.app.ActivityThread.access$800(ActivityThread.java:154)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1308)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5273)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:908)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:703)
循环代码
public List<Map<String,Object>> getData() {
for (int i=0;i<icon.length;i++) {
Map<String, Object> map = new HashMap<String, Object>();
map.put("image",icon[i]);
map.put("text",iconName[i]);
dataList.add(map);
}
return dataList;
}