这是一个书后实例,是structs + hibernate的项目,但用到了Spring中的PageListHolder。按理说不该有错,仔细查看了整个传值流程也找不出问题。进入网络商城首页,点击书籍——点击computerbo 然后就出现以下空指针错误:
javax.servlet.jsp.JspException: An error occurred while evaluating custom action attribute "items" with value "${itemList.pageList}": An error occurred while getting property "pageList" from an instance of class org.springframework.beans.support.PagedListHolder (java.lang.NullPointerException)愿意帮忙的朋友可以把邮箱留下,我会把建表语句和这小项目都发过去。 
最后希望大家能告诉我问题所在,谢谢了~~

解决方案 »

  1.   

    这个问题我以前也遇到过,不过解决方法不是很清楚了,首先java.lang.NullPointerException也就是说你${itemList.pageList}"中的pageList没有获取到,getting property "pageList"按到你的Action中设置了全局变量pageList?javax.servlet.jsp.JspException,你的Jsp页面写错了,老熊多帖点代码出来呀,问题就好解决了
      

  2.   

    ${itemList.pageList},对了你这个写法有点问题呀,你的pageList是用保存在什么范围里的呀,如果是session的吗话:${sessionScope.pageList},如果是request:${request.pageList}
      

  3.   

    恩,都查看了就是没发现问题。相关页面只有category.jsp和Product.jsp。
    在category.jsp页面:http://localhost:8088/netshop/shop/viewCategory.do?categoryId=software
    点击产品"KingSoft"后跳转至Product.jsp页面:http://localhost:8088/netshop/shop/viewProduct.do?productId=KingSoft
    也就是在这个页面出现了相关异常:org.apache.jasper.JasperException: javax.servlet.ServletException: javax.servlet.jsp.JspException: An error occurred while evaluating custom action attribute "items" with value "${itemList.pageList}": An error occurred while getting property "pageList" from an instance of class org.springframework.beans.support.PagedListHolder (java.lang.NullPointerException)javax.servlet.ServletException: javax.servlet.jsp.JspException: An error occurred while evaluating custom action attribute "items" with value "${itemList.pageList}": An error occurred while getting property "pageList" from an instance of class org.springframework.beans.support.PagedListHolder (java.lang.NullPointerException)root cause java.lang.NullPointerException
      

  4.   

    category.jsp 相关代码如下:<table width="47" height="27"  border="2" align="left" >
    <tr><td >
    <a href="<c:url value="/shop/index.do"/>"><b><font size="2"/><bean:message key="netshop.mainu"/></b></td>
    </tr>
    </table><p>
    <center>
      
      </center>
    <table width="80%"  border="1" align="center"  >
      <tr >  <td width="47%"><b><bean:message key="netshop.productid"/></b></td>  <td width="53%"><b><bean:message key="netshop.category"/></b></td>  </tr>
    <c:forEach var="product" items="${productList.pageList}">
      <tr >
      <td><b><a href="<c:url value="/shop/viewProduct.do"><c:param name="productId" value="${product.productId}"/></c:url>">
      <font color="RED"><c:out value="${product.productId}"/></font>
    </a></b></td>
      <td><c:out value="${product.name}"/></td>
      </tr>
    </c:forEach>
      <tr><td>
      <c:if test="${!productList.firstPage}">
        <a href="?page=previous"><font color="white"><B>&lt;&lt; <bean:message key="netshop.prepage"/></B></font></a>
      </c:if>
      <c:if test="${!productList.lastPage}">
        <a href="?page=next"><font color="white"><B><bean:message key="netshop.nextpage"/> &gt;&gt;</B></font></a>
      </c:if>
      </td></tr>
    </table>
      

  5.   

    Product.jsp 相关代码如下:<table width="20"  border="2" align="left" >
    <tr><td >
    <a href="<c:url value="/shop/viewCategory.do"><c:param name="categoryId" value="${product.categoryId}"/></c:url>">
      <b><font color="BLACK" size="2"><c:out value="${product.name}"/></font></b>
    </a>
    </td></tr>
    </table><p><center>
      <b><font size="4"><c:out value="${product.name}"/></font></b>
    </center><table width="100%"  border="2" align="center" >
      <tr >  <td><b><bean:message key="netshop.itemid"/></b></td>  <td><b><bean:message key="netshop.productid"/></b></td>  <td><b><bean:message key="netshop.description"/></b></td>  <td><b><bean:message key="netshop.price"/></b></td>  <td>&nbsp;</td>  </tr>
    <c:forEach var="item" items="${itemList.pageList}">
      <tr >
      <td><b>
      <a href="<c:url value="/shop/viewItem.do"><c:param name="itemId" value="${item.itemId}"/></c:url>">
        <c:out value="${item.itemId}"/>
      </a></b></td>
      <td><c:out value="${item.productId}"/></td>
      <td>
        <c:out value="${item.attribute1}"/>
        <c:out value="${item.attribute2}"/>   
        <c:out value="${product.name}"/>
      </td>
      <td><fmt:formatNumber value="${item.listPrice}" pattern="$#,##0.00"/></td>
      <td><a href="<c:url value="/shop/addItemToCart.do"><c:param name="workingItemId" value="${item.itemId}"/></c:url>">
        <bean:message key="netshop.puttocart"/>
      </a></td>
      </tr>
    </c:forEach>
      <tr><td>
      <c:if test="${!itemList.firstPage}">
        <a href="?page=previous"><font color="white"><B>&lt;&lt; <bean:message key="netshop.prepage"/></B></font></a>
      </c:if>
      <c:if test="${!itemList.lastPage}">
        <a href="?page=next"><font color="white"><B><bean:message key="netshop.nextpage"/> &gt;&gt;</B></font></a>
      </c:if>
      </td></tr>
    </table>
      

  6.   

    先看一看那个list在没传到页面之前,他是不是null,这样才能看出是查询时出错,还是传到页面时出错
      

  7.   

    tomcat 报的是查询错误貌似,但我就是没找出来......这是这个项目的下载地址:http://www.rayfile.com/zh-cn/files/41626cde-eb58-11df-b4cb-0015c55db73d/
      

  8.   

    System.out.pribtln("查错最好用");
      

  9.   

    <a href="<c:url value="/shop/viewItem.do"><c:param name="itemId" value="${item.itemId}"/></c:url>">
      <c:out value="${item.itemId}"/>
      </a></我觉得这种代码很烦躁
      

  10.   

    空指针异常。在本例中没人可以帮你解决。因为我们没有获取完整的代码。
    空指针异常是众多异常中最好调试的异常之一。因为你的这个代码过多,可以删除一些代码,缩小范围。并借助debug查看每一步的运行结果。