java.lang.ClassCastException: java.lang.String cannot be cast to java.util.Map
for(int i=0;i<list.size();i++){
map1 = (Map) list.get(i);
System.out.println(map1);
map=multi_sender.imp(map1);
}
这是代码。
map1 = (Map) list.get(i);
报错:java.lang.String cannot be cast to java.util.Map
。请大家帮帮忙,谢谢 --------------------编程问答-------------------- 类型转换错误,string转换成map类型不对,呵呵 --------------------编程问答-------------------- 晕,你list里add的是String类型的,
你非要把String型的强制转换成Map型的,
人家能答应么。。。 --------------------编程问答-------------------- 就是想把list转换成map的,我在别的项目就这样写的没问题,麻烦再帮忙想想还有什么原因 --------------------编程问答-------------------- list能直接转换成map?那就麻烦你把代码贴全点吧。。。 --------------------编程问答-------------------- public ModelAndView importmulti_sender(HttpServletRequest request) {
Map map = RequestUtil.getMap(request);
multi_sender=new Multi_Sender();
try {
File file = new File(request.getParameter("excelpath"));
InputStream in = new FileInputStream(file);
Workbook ws = Workbook.getWorkbook(in);
jxl.Sheet rs = ws.getSheet(0);
if (rs.getRows() < 1) {
request.getSession().setAttribute("msg", "Excel中没有数据");
}
int c = 0, error = 0, count = 0;
//String accountid = "";
String sender = "";
List list = new ArrayList();
for (int i = 1; i < rs.getRows(); i++) {
c++;
//accountid=rs.getCell(0,i).getContents();
sender = rs.getCell(1, i).getContents();//第二列,第i行
if (sender == null || sender.equals("")) {
error++;
continue;
}
if (!sender.matches("^(?:13[012]|145|15[56]|18[56])-?\\d{8}$")){
error++;
continue;
}
//list.add(accountid);
list.add(sender);
count++;
}
Map map1=null;
if (list.size() > 0) {
for(int i=0;i<list.size();i++)
{
map1 = (Map) list.get(i);//这条出错
map=multi_sender.imp(map1);
}
map.put("result", true);
map.put("totalNum", c);
map.put("errorNum", error);
map.put("countNum", count);
}
} catch (Exception e) {
map.put("result", false);
e.printStackTrace();
}
return new ModelAndView("jsonView", map);
}
谢谢,谢谢,帮忙看看
补充:Java , Web 开发