我正在研究sax XML解析。
Logcat错误,如...
java.lang.IndexOutOfBoundsException: Invalid index 11, size is 11 我在以下位置得到错误
map.put("pubdate", sitesList.getPubdate().get(i));
for (int i = 0; i < sitesList.getName().size(); i++) {
System.out.println("value of i==============>"+i);
HashMap<String, String> map = new HashMap<String, String>();
System.out.println("\nvalue of title==============>"+ sitesList.getName().get(i));
map.put("title", sitesList.getName().get(i));
map.put("pubdate", sitesList.getPubdate().get(i));
map.put("desc", sitesList.getDesc().get(i));
items.add(map);
}谢谢大家。
发布于 2012-05-31 19:33:29
感谢所有人,我终于得到了我的问题的解决方案,这里的sitesList.getName()比sitesList.getPubdate()大,所以现在我使用
for (int i= 0;i< sitesList.getPubdate().size();i++)代替
for (int i= 0;i< sitesList.getName().size();i++)
for (int i = 0; i < sitesList.getPubdate().size(); i++) {
System.out.println("value of i==============>"+i);
HashMap<String, String> map = new HashMap<String, String>();
map.put("title", sitesList.getName().get(i));
map.put("pubdate", sitesList.getPubdate().get(i));
map.put("desc", sitesList.getDesc().get(i));
items.add(map);
}发布于 2012-05-31 18:10:23
是否确定sitesList.getName()的大小与sitesList.getPubdate()的大小相同?
因为该异常的唯一原因是sitesList.getName()比sitesList.getPubdate()大:)
发布于 2012-05-31 18:09:04
我想这里有sitesList的大小,
使用sitesList.size() 而不是 sitesList.getName().size()
for (int i = 0; i < sitesList.size(); i++) {
System.out.println("value of i==============>"+i);
HashMap<String, String> map = new HashMap<String, String>();
System.out.println("\nvalue of title==============>"+ sitesList.get(i).getName());
map.put("title", sitesList.get(i).getName());
map.put("pubdate", sitesList.get(i).getPubdate());
map.put("desc", sitesList.get(i).getDesc());
items.add(map);
}https://stackoverflow.com/questions/10831465
复制相似问题