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

java.lang.NumberFormatException: null
当jsp页面中的该代码提交
HTML code
<form name="pagination"  action="PagInationServlet" method="post">
        <input type="hidden" name="result1" value="${requestScope.result1}">
        <input type="hidden" name="result2" value="${requestScope.result2}">
    <input type="hidden" name="result3" value="${requestScope.result3}">
    <select  name="pageForm"  onchange="choosePageIndex()">
        <c:forEach items="${requestScope.listPage}" var="page">
            <option value="${page }" >${page }</option>
        </c:forEach>
    </select>
</form>


到了
Java code
public void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        
        String result1 = request.getParameter("result1");
        String result2 = request.getParameter("result2");
        String result3 = request.getParameter("result3");
         lastZxBean lastZx = new lastZxBean();
        String temp = request.getParameter("choosePageIndex");
        Integer temp2 = Integer.valueOf(temp);
        int choosePageIndex = temp2.intValue();
        List list = lastZx.query(choosePageIndex);
        request.setAttribute("objResult", list);
        request.setAttribute("result1", result1);
        request.setAttribute("result2", result2);
        request.setAttribute("result3", result3);
        request.getRequestDispatcher("jsps/list.jsp").forward(request, response);        
    }


报出异常
Java code
java.lang.NumberFormatException: null
    at java.lang.Integer.parseInt(Integer.java:415)
    at java.lang.Integer.valueOf(Integer.java:553)
    at com.xindun.controller.PagInationServlet.doGet(PagInationServlet.java:55)
    at com.xindun.controller.PagInationServlet.doPost(PagInationServlet.java:79)


具体指向了
Java code
String temp = request.getParameter("choosePageIndex");
        Integer temp2 = Integer.valueOf(temp);
        int choosePageIndex = temp2.intValue();

但是我在编写的时候 没有出错的啊 怎么回事呢?

------解决方案--------------------
编译没错,运行出错了
String temp = request.getParameter("choosePageIndex");
这个choosePageIndex表单里没有啊!
怎么传来的?
------解决方案--------------------
很显然应该是pageForm,而不是choosePageIndex
------解决方案--------------------
Integer temp2 = Integer.valueOf(temp);
这种转换最好try catch一下,保证非数字问题,做下响应处理
------解决方案--------------------
你把一个 "null"的字符串转换为INTEGER 当然会出错(之所以出的不是空指针是因为你这个NULL是个字符串。。。)
------解决方案--------------------
chooseP