日期:2014-05-17  浏览次数:20784 次

数据类型转换问题
报错的地方
Java code

java.lang.NumberFormatException: For input string: "on"
    at java.lang.NumberFormatException.forInputString(Unknown Source)
    at java.lang.Integer.parseInt(Unknown Source)
    at java.lang.Integer.parseInt(Unknown Source)
    at com.bellsent.servlet.EditManagementServlet.doPost(EditManagementServlet.java:66)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:261)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:581)
    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
    at java.lang.Thread.run(Unknown Source)


我的代码:
Java code

String dType = request.getParameter("dType");
        String dIpAdd = request.getParameter("dIpAdd");    
        int dPort = Integer.parseInt(request.getParameter("dPort"));        
        
        String dDescription = request.getParameter("dDescription");
        String dUsrName = request.getParameter("dUsrName");
        String dUsrPwd = request.getParameter("dUsrPwd");
        int videoChannels = Integer.parseInt(request.getParameter("videoChannels"));        
        String vch1 = request.getParameter("vch1");
        String vch2 = request.getParameter("vch2");


这个错误貌似是说数据转换问题,或者是其他问题,纠结了好长时间,也baidu了好长时间,不知道怎么解决?求帮助~~~

------解决方案--------------------
Integer.parseInt之前先打印一下变量不就知道了
------解决方案--------------------

错误在你的 EditManagementServlet.java:66行 ,数据类型错误,java.lang.NumberFormatException: For input string: "on" 你贴的代码里没有66行
------解决方案--------------------
是不是String类型转成int型的转错了啊
换种方式转试试 

Integer intObj = new Integer(user.getWorkendtime());
int inte = intObj.intValue();

------解决方案--------------------
java.lang.NumberFormatException: For input string: "on"
at java.lang.NumberFormatException.forInputString(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)

at com.bellsent.servlet.EditManagementServlet.doPost(EditManagementServlet.java:66)


int dPort = Integer.parseInt(request.getParameter("dPort")); 

request.getParameter("dPort") 这个值应该为 "on"了,不能转换
------解决方案-----------