当前位置: 代码迷 >> Java Web开发 >> [求助]java.lang.NumberFormatException: null
  详细解决方案

[求助]java.lang.NumberFormatException: null

热度:838   发布时间:2006-11-05 19:53:33.0
[求助]java.lang.NumberFormatException: null



一直说“int newsid = Integer.parseInt(request.getParameter("newsid"));”有问题啊

这个是我action:

public ActionForward execute(
ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response) {
ModifyForm modifyForm = (ModifyForm) form;
// TODO Auto-generated method stub
int newsid = Integer.parseInt(request.getParameter("newsid"));
List list = new ArrayList();
NewDAO newDAO = new NewDAO();
int i = 0;
list = newDAO.shownews(newsid);
request.setAttribute("main",list);
// return mapping.findForward("success");

System.out.println(modifyForm);
System.out.println("修改的是:"+newsid+"号");
i = newDAO.modifynews(modifyForm,newsid);
if(i == 1){
System.out.println("成功转入");
return mapping.findForward("success");
}else{
System.out.println("不成功转入");
return mapping.findForward("failure");
}

}

下面是写的DAO里面的:
public int modifynews(ModifyForm form,int id){
int record = 0;
System.out.println("要修改的ID号:"+id);
PreparedStatement ps = null;
String sql = "update NEWS set TOPIC = ?,CONTENT = ? where NEWS_ID = ?";
try {
ps = conn.prepareStatement(sql);
ps.setString(1,form.getTopic());
ps.setString(2,form.getContent());
ps.setInt(3,id);
record = ps.executeUpdate();
System.out.println("修改成功");
} catch (SQLException e) {
// TODO 自动生成 catch 块
e.printStackTrace();
System.out.println("修改失败");
}
return record;
}

下面是报的错:
修改的是:2号
要修改的ID号:2

修改成功
成功转入
2006-11-5 19:35:15 org.apache.struts.action.RequestProcessor processException
警告: Unhandled Exception thrown: class java.lang.NumberFormatException
2006-11-5 19:35:15 org.apache.catalina.core.StandardWrapperValve invoke
严重: Servlet.service() for servlet action threw exception
java.lang.NumberFormatException: null
at java.lang.Integer.parseInt(Integer.java:415)
at java.lang.Integer.parseInt(Integer.java:497)
at com.thinkbank.zhengh.struts.action.ModifyAction.execute(ModifyAction.java:49)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:419)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:224)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1194)
at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at com.thinkbank.zhengh.filter.NewsFilter.doFilter(NewsFilter.java:24)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
at java.lang.Thread.run(Thread.java:595)

我自己把一些有问题的地方打印出来了,打印表明我要传入的id已经传入成功了
但是还是一直都报“int newsid = Integer.parseInt(request.getParameter("newsid"));”

小菜鸟初学JAVA 调了一下午还没调出来,请高人指点,不胜感激

[此贴子已经被作者于2006-11-8 0:26:08编辑过]

搜索更多相关主题的帖子: java  lang  null  newsid  form  

----------------解决方案--------------------------------------------------------
java.lang.NumberFormatException: null
这句话不是已经告诉你错在哪里了吗?
是数字格式异常,你想把"abcd"转化成数字是不可能的

----------------解决方案--------------------------------------------------------
我传入的数据是整型的不是字符型的啊
int newsid = Integer.parseInt(request.getParameter("newsid"));
这里的newsid就是整型的
----------------解决方案--------------------------------------------------------
但是如果你没有输入的时候,null怎么转化成int?
你的错误信息不是提示你了吗,是把null转化成int的时候出错了
----------------解决方案--------------------------------------------------------
这是dao里面打印出来的 System.out.println("要修改的ID号:"+id);
这里已经把要打印的是传入的"newsid"
打印结果 :要修改的ID号:2
这就是说我传入的参数 newsid 并不是null啊
而且在dao里面程序也已经把 modifynews()运行完了
action里面也执行到return mapping.forward()了


----------------解决方案--------------------------------------------------------

另外想请教如何在struts 进行自动刷新功能啊
<meta http-equiv="refresh" content="n;url=url">
这个没有起作用


----------------解决方案--------------------------------------------------------
at com.thinkbank.zhengh.struts.action.ModifyAction.execute(ModifyAction.java:49)
看看你的这个程序的第49行

----------------解决方案--------------------------------------------------------

问题解决了
at com.thinkbank.zhengh.struts.action.ModifyAction.execute(ModifyAction.java:49)
也就是 int newsid = Integer.parseInt(request.getParameter("newsid"));
确实有问题
我在action里面一共经过了2次dao的访问,
可能是第一次的newsid为空,第二次就有值了
报的错是报第一次使用到的newsid
这样想了,我就把aciton分开写了 就没有错了

明天就要拿去答辩了,今天早点休息了~~~~
谢谢你了 斑竹


----------------解决方案--------------------------------------------------------
恭喜你,终于解决了

----------------解决方案--------------------------------------------------------
恭喜你,终于解决了


----------------解决方案--------------------------------------------------------
  相关解决方案