问题描述
- java.lang.NumberFormatException:
-
刚注册没分 担待啊
这两段代码问题
int firstcount=(Integer.valueOf(currentpage)-1)*Integer.valueOf(recordpage);
int lastcount=Integer.valueOf(recordpage);严重: Servlet.service() for servlet [BasesAction] in context with path [/sss] threw exception
java.lang.NumberFormatException: For input string: "0 "
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
at java.lang.Integer.parseInt(Integer.java:492)
at java.lang.Integer.valueOf(Integer.java:582)
at www.action.BasesAction.doGet(BasesAction.java:76)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:243)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:201)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:163)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:108)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:556)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:401)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:242)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:267)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:245)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:260)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:722)
解决方案
recordpage后面多了一个空格,所以没法解析
recordpage
->
recordpage.trim()看看
解决方案二:
For input string: "0 "
数字0 后面有空格 、
解决方案三:
currentPage或recordPage中值有空格,建议转换前先判断字符串是否为null,不为null就调用trim方法清除空格
解决方案四:
数据格式不对,所以转换错误
解决方案五:
recordpage变量是“0 ”,没法解析成数字。只有整数值的字符串才能转化