作业帮 > 综合 > 作业

数据转换错误java.lang.numberformatexception null java.lang.integer

来源:学生作业帮 编辑:大师作文网作业帮 分类:综合作业 时间:2024/11/12 00:33:12
数据转换错误java.lang.numberformatexception null java.lang.integer.parseint integer.java
org.apache.jasper.JasperException:An exception occurred processing JSP page /reply.jsp at line 6
3:
4:
8:
9:
Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:515)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:426)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
root cause
java.lang.NumberFormatException:null
java.lang.Integer.parseInt(Integer.java:415)
java.lang.Integer.parseInt(Integer.java:497)
org.apache.jsp.reply_jsp._jspService(reply_jsp.java:57)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:384)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
note The full stack trace of the root cause is available in the Apache Tomcat/6.0.10 logs.
数据转换错误java.lang.numberformatexception null java.lang.integer
错误出现原因:数字格式化异常,如果id、rootId 是null,你的代码是要把null转换成int类型,就会出错,可以修改代码如下:
int id = 0;
int rootId = 0;
if(request.getParameter("id") != null && !"".equals(request.getParameter("id"))) {
id = Integer.parseInt(request.getParameter("id"));
}
if(request.getParameter("rootId") != null && !"".equals(request.getParameter("rootId"))) {
rootId = Integer.parseInt(request.getParameter("rootId"));
}