这是action中的文件,debug到这里List list = SpeakforServingService.getAll(dc);就报空指针了,谢谢各位帮忙看下!
报错信息如下:
2009-09-22 14:38:35,125 WARN [http-8082-4] (RequestProcessor.java:528) WARN - Unhandled Exception thrown: class java.lang.NullPointerException
2009-9-22 14:38:37 org.apache.catalina.core.ApplicationContext log
信息: java.lang.NullPointerExceptionaction的代码:
public ActionForward execute(ActionMapping mapping,
ActionForm form, HttpServletRequest request,
HttpServletResponse response) throws Exception {
ServicesForm servicesForm = (ServicesForm) form; String names = request.getParameter("names");
DetachedCriteria dc = DetachedCriteria
.forClass(Services.class);
if (names != null && !names.equals("")) {
dc.add(Restrictions.like("names", names,
MatchMode.ANYWHERE));
}
List list = SpeakforServingService.getAll(dc);
int totalrow = list.size();
int perpagerow = servicesForm.getPerpagerow();
int currentpage = servicesForm.getCurrentpage();
if (currentpage == 0) {
servicesForm.setCurrentpage(1);
}
int start = (currentpage - 1) * perpagerow;
List pageList = SpeakforServingService.findPageList(dc,
start, perpagerow);
servicesForm.setTotalrow(totalrow); request.setAttribute("servicesList", pageList);
request.setAttribute("servicesForm", servicesForm);
request.setAttribute("names", names);
return mapping.findForward("toSpeakfor");
}}debug到这个地方:List list = SpeakforServingService.getAll(dc);就报错了!
报错信息如下:
2009-09-22 14:38:35,125 WARN [http-8082-4] (RequestProcessor.java:528) WARN - Unhandled Exception thrown: class java.lang.NullPointerException
2009-9-22 14:38:37 org.apache.catalina.core.ApplicationContext log
信息: java.lang.NullPointerExceptionaction的代码:
public ActionForward execute(ActionMapping mapping,
ActionForm form, HttpServletRequest request,
HttpServletResponse response) throws Exception {
ServicesForm servicesForm = (ServicesForm) form; String names = request.getParameter("names");
DetachedCriteria dc = DetachedCriteria
.forClass(Services.class);
if (names != null && !names.equals("")) {
dc.add(Restrictions.like("names", names,
MatchMode.ANYWHERE));
}
List list = SpeakforServingService.getAll(dc);
int totalrow = list.size();
int perpagerow = servicesForm.getPerpagerow();
int currentpage = servicesForm.getCurrentpage();
if (currentpage == 0) {
servicesForm.setCurrentpage(1);
}
int start = (currentpage - 1) * perpagerow;
List pageList = SpeakforServingService.findPageList(dc,
start, perpagerow);
servicesForm.setTotalrow(totalrow); request.setAttribute("servicesList", pageList);
request.setAttribute("servicesForm", servicesForm);
request.setAttribute("names", names);
return mapping.findForward("toSpeakfor");
}}debug到这个地方:List list = SpeakforServingService.getAll(dc);就报错了!
可能是add方法没有执行,
一步一步测试。
int totalrow = list.size();list是null吗?是的话
list.size(); 错啦! 等价(null.size())!