JAVA高手进啊...

来源:百度知道 编辑:UC知道 时间:2024/09/21 22:10:06
小弟在做一个项目的购物车迭代时提示Cannot create iterator for this collection
String s=request.getParameter("id");
List<Products> list=productsBiz.getProduct(Integer.parseInt);//改为前页面session传值
Products product=null;
if (list!=null&&list.size()!=0) {
product=new Products();
product=list.get(0);
session.setAttribute("proCar", product);
}
ProductCar pCar=new ProductCar(product,1);
Map<Integer, ProductCar> car=(Map<Integer, ProductCar>)session.getAttribute("car");
if (car==null) {
car=new HashMap<Integer, ProductCar>();
session.setAttribute("car", car);
}
ProductCar myCar=car.get(product.getProductId());
if (myCar!=null) {
myCar.setCount(myCar.getCount()+1);
}
else {
car.put(product.getProductId(), pCar);
}

if (car!=null) {
Set kSet=car.keySet();
Iterator&l

直接循环你的Map:car
<c:forEach var="carItem" items="${car}">
<c:out value="${carItem.key}"/> = <c:out value="${carItem.value}"/><br>
</c:forEach>

Cannot create iterator for this collection

空指针错?