专注收集记录技术开发学习笔记、技术难点、解决方案
网站信息搜索 >> 请输入关键词:
您当前的位置: 首页 > Java Exception

用SSH整合实现的分页出现了空指针异常

发布时间:2010-06-05 12:19:47 文章来源:www.iduyao.cn 采编人员:星星草

用SSH整合实现的分页出现了空指针异常:

分页时出现的空指针异常:
错误是:
java.lang.NullPointerException
com.jxc.struts.actions.AddressAction.list(AddressAction.java:40)
sun.reflect.GeneratedMethodAccessor63.invoke(Unknown Source)
sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
java.lang.reflect.Method.invoke(Unknown Source)
org.apache.struts.actions.DispatchAction.dispatchMethod(DispatchAction.java:270)
org.apache.struts.actions.DispatchAction.execute(DispatchAction.java:187)
org.apache.struts.actions.DispatchAction$$FastClassByCGLIB$$d3d27916.invoke( <generated>)
net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy.java:149)
org.springframework.aop.framework.Cglib2AopProxy$CglibMethodInvocation.invokeJoinpoint(Cglib2AopProxy.java:695)
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:139)
org.springframework.aop.framework.adapter.MethodBeforeAdviceInterceptor.invoke(MethodBeforeAdviceInterceptor.java:50)
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:161)
org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(Cglib2AopProxy.java:630)
com.jxc.struts.actions.AddressAction$$EnhancerByCGLIB$$32f25b28.execute( <generated>)
org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:431)
org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:236)
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:414)
javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:96)
org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:75)
其中PageForm有两个属性pageSize和pageNo,以及setter和getter方法。
Pager类的代码如下:
package com.jxc.struts.util;

import java.util.ArrayList;
import java.util.List;

public class Pager {

//页面大小
protected int[] pageSizeList = {10,25,50,200,300,500};
//一页显示的记录数
protected int pageSize = Constants.pageSize;
//当前页码
protected int pageNo = Constants.pageNo;
//记录总数
protected int rowCount = 0;
//总页数
protected int pageCount = 1;
//起始行数
protected int startIndex = 1;
//结束行数
protected int endIndex = 1;
//第一页
protected int firstPageNo = 1;
//前一页
protected int prePageNo = 1;
//下一页
protected int nextPageNo = 1;
//最后一页
protected int lastPageNo = 1;
//结果集存放List
public List resultList;

//构造函数
public Pager(int pageSize,int pageNo,int rowCount,List resultList){
this.pageSize = pageSize;
this.pageNo = pageNo;
this.rowCount = rowCount;
this.resultList = resultList;

if(rowCount % pageSize == 0){
this.pageCount = rowCount / pageSize;
}else{
this.pageCount = rowCount / pageSize + 1;
}
this.startIndex = pageSize*(pageNo - 1);
this.endIndex = this.startIndex + resultList.size();

this.lastPageNo = this.pageCount;

if(this.firstPageNo > 1){
this.prePageNo = this.pageNo - 1;
}
if(this.pageNo == this.lastPageNo){
this.nextPageNo = this.lastPageNo;
}else{
this.nextPageNo = this.pageNo + 1;
}
}

//输出每页记录数的数值列表
public Object[] getPageSizeIndexs(){
List result = new ArrayList(pageSizeList.length);
for(int i = 0;i < pageSizeList.length;i++){
result.add(String.valueOf(pageSizeList[i]));
}
Object[] indexs = (result.toArray());
return indexs;
}

//输出页码的数值列表
public Object[] getPageNoIndexs(){
List result = new ArrayList(pageCount);
for(int i = 0; i < pageCount;i++){
result.add(String.valueOf(i+1));
}
Object[] indexs = (result.toArray());
return indexs;
}

public List getResultList() {
return this.resultList;
}
//
// public void setResultList(List resultList) {
// this.resultList = resultList;
// }
//
// public Pager(){
//
// }
}
在AddressDAO类中有一个方法:
public Pager findPagerByUsername(String username, int pageNo, int pageSize){
try {
Session session = getHibernateTemplate().getSessionFactory()
.getCurrentSession();

// 设置查询条件     

友情提示:
信息收集于互联网,如果您发现错误或造成侵权,请及时通知本站更正或删除,具体联系方式见页面底部联系我们,谢谢。

其他相似内容:

热门推荐: