java.lang.NumberFormatException: null 找不到原因,请大神帮忙

qq_39781680 2017-08-25 06:38:05
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);


}
...全文
2188 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
清晨v 2017-08-25
  • 打赏
  • 举报
回复
楼上正解!1!!!!
李德胜1995 2017-08-25
  • 打赏
  • 举报
回复
at web.MainServlet.toUpdateCost(MainServlet.java:120)120行格式化异常。。。打印一下字符串id是不是null???

679

社区成员

发帖
与我相关
我的任务
社区描述
智能路由器通常具有独立的操作系统,包括OpenWRT、eCos、VxWorks等,可以由用户自行安装各种应用,实现网络和设备的智能化管理。
linuxpython 技术论坛(原bbs)
社区管理员
  • 智能路由器社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧