JAVA jsoup解析网页时,并以列表方式输出,但采用键值对方式时出现错误,跪求解决!!!!

部分代码:public static List> getKcList(String str) {
List> kcList = new ArrayList>();
Document doc = Jsoup.parse(str);
Elements datas = doc.getElementsByTag("table");
Element data = datas.get(0);
Elements trs = data.getElementsByTag("tr");
for (int i = 0; i < trs.size(); i++) {

       Elements tds = trs.get(i).select("td[rowspan=2]");
       for (int j = 0; j < tds.size(); j++) {



           if (!"".equals(tds.get(j).text())) {

                   kcList.add(getkcMap(tds.get(j).text()));

               }
           }

}
Log.i("Td","kcList"+kcList.size());
// Log.i("Th","kcList"+kcList.size());
return kcList;
}
/***************************
* 数据封装
****************************/
private static MapgetkcMap(String str){
String courseInfo[]=new String[]{
"课程编号:","课程名称:","教师号:","教师姓名:",
"上课时间:", "上课教室:","答疑时间:","答疑地点:",

    };
    String sCourse[] = str.split("\n");
    int i = 0;
    Map<String, String> map = new HashMap<String, String>();
    for (;i < sCourse.length; i++) {
        String s = sCourse[i];
        map.put(courseInfo[i], s);
        Log.i("Td", i + courseInfo[i] + "==" + s);
    }

    return map;

}

}

显示时: private void toShow(){
StringBuffer sb = new StringBuffer();
for(Mapmap:kcList){
for(String key : map.keySet()) {
if(!"".equals(map.get(key)))
sb.append(key).append(" ").append(map.get(key)).append(" ");
}
sb.append("\n----------------------\n");
}

  kb.setText(sb.toString());
}

}

显示结果出现错误如下:图片说明

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问