java.lang.NumberFormatException: null 找不到原因,请大神帮忙
java.lang.NumberFormatException: null
at java.lang.Integer.parseInt(Integer.java:454)
at java.lang.Integer.<init>(Integer.java:677)
at web.MainServlet.toUpdateCost(MainServlet.java:120)
at web.MainServlet.service(MainServlet.java:35)
报错位置
代码贴下面!!
// 修改数据
protected void updateCost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
//这里使用的是get发送。解决乱码的方法如下
req.setCharacterEncoding("utf-8");
//以下为接收数据:Parameter为参数
String name=req.getParameter("name");
String basicDuration=req.getParameter("basicDuration");
String basicCost=req.getParameter("basicCost");
String unitCost=req.getParameter("unitCost");
String descr=req.getParameter("descr");
String costType=req.getParameter("costType");
// 保存数据
Cost c=new Cost();
c.setName(name);
c.setCostType(costType);
c.setDescr(descr);
/*
* 这里判断解决选择套餐时,以下为空会报错,所有要判断
因为basicCost,basicCost,unitCost类型不是字符串,
所有要转成自己的类型。
*/
if (basicDuration!=null&& !basicDuration.equals("")) {
c.setBasicDuration(new Integer(basicDuration));
}
if (basicCost!=null&& !basicCost.equals("")) {
c.setBasicCost(new Double(basicCost));
}
if (unitCost!=null&& !unitCost.equals("")) {
c.setUnitCost(new Double(unitCost));
}
//封装这些对象,实例化dao
costDao dao=new CostDaoImpl();
dao.save(c);
// 重定向到查询功能,也就是重新回到查询页面
// 当前路径:netctoss2/addCost.do
// 目标路径:netctoss2/findCost.do
res.sendRedirect("findCost.do");
// 以上对于代码合理的管理,以及处理,之后我们会学习spring框架来进行处理
}
}
// 打开资费修改页面方法
protected void toUpdateCost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
// 接收Id
String id=req.getParameter("id");
System.out.println(id);
// 根据参数查询要修改的这条数据
costDao dao=new CostDaoImpl();
//用字符串接收的所有要转成integer;
Cost cost=dao.findById(new Integer(id));
//数据传入request里面转发到JSP
req.setAttribute("cost", cost);
req.getRequestDispatcher("WEB-INF/cost/update.jsp").forward(req, res);
}