首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2SE开发 >

关于ArrayList类的add()方法,该如何处理

2012-03-23 
关于ArrayList类的add()方法最近自己在写一个极其简易的快速web开发包,写到分页的部分的时候,出现这个问题

关于ArrayList类的add()方法
最近自己在写一个极其简易的快速web开发包,写到分页的部分的时候,出现这个问题

public   class   Pagination   {
private   int   pageCount;   //   页数

private   int   currentPageNo   =   1;   //   当前页

private   int   recordNumPerPage   =   10;   //   每页记录数

private   int   startRecordId   =   0;   //   本页开始记录的起始位置

private   int   recordNumSum;   //   记录总条数

private   ArrayList <RowModel>   pagedList;

private   ArrayList <RowModel>   listForPagination;

public   Pagination(ArrayList <RowModel>   listForPagination,int   recordNumPerPage,   int   currentPageNo)   {
this.setListForPagination(listForPagination);
this.setRecordNumPerPage(recordNumPerPage);
this.setCurrentPage(currentPageNo);
this.setRecordNumSum(listForPagination.size());
}
.....
public   ArrayList <RowModel>   getPagedList()   {
if   (this.recordNumSum   %   this.recordNumPerPage   ==   0)   {
this.setPageCount(this.recordNumSum   /   this.recordNumPerPage);
}   else   {
this.setPageCount(this.recordNumSum   /   this.recordNumPerPage   +   1);
}
this.setStartRecordId(this.recordNumPerPage   *   (this.currentPageNo   -   1));
System.out.println( "[startRecordId]   : "   +   this.startRecordId);
System.out.println( "[recordNumPerPage]   : "   +   this.recordNumPerPage);
int   startIndex   =   this.startRecordId;
int   endIndex   =   startIndex   +   this.recordNumPerPage;
System.out.println( "[startIndex]: "   +   startIndex
+   "                       [endIndex]: "   +   endIndex);
for   (int   index   =   startIndex;   index   <   endIndex;   index++)   {
if   (index   > =   listForPagination.size())
break;
try   {
pagedList.add(listForPagination.get(index));
}   catch   (Exception   e)   {

}

}
return   pagedList;
}
....
}


这样一个类,省略了一些setter和getter,发现pagedList.add(listForPagination.get(index));没有起作用。。。
最后打出来的pagedList还是null,请问为什么

注listForPagination.size()=17这个倒是没问题

[解决办法]
这样的问题一般单步跟踪能找到问题,估计是空指针的问题,估计是setter或getter方法的问题
[解决办法]
似乎没看见 pageList 的初始化语句

pageList = new ArrayList();

热点排行
Bad Request.