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

空指针异常求帮助
出错提示
java.lang.NullPointerException
at com.tchManage.dao.PostDAO.findAllPost(PostDAO.java:39)
at com.tchManage.servlet.PostController.findAll(PostController.java:131)
at com.tchManage.servlet.PostController.doPost(PostController.java:40)
at com.tchManage.servlet.PostController.doGet(PostController.java:147)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:936)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1004)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:1822)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:619)



com.tchManage.dao.PostDAO.java
public List<Post> findAllPost(int currentPage) throws SQLException,ClassNotFoundException{
try{
ResultSet rs=pl.pageList(5,"userinfo",currentPage,"desc","id");(39)
System.out.println(rs);
rs.beforeFirst();
List<Post> list=new ArrayList<Post>();

while(rs.next()){
Post u=new Post();
u.setId(rs.getInt("id"));
u.setTitle(rs.getString("title"));
u.setContent(rs.getString("content"));
u.setTime(rs.getString("time"));

list.add(u);
}
return list;

}catch(Exception e){
e.printStackTrace();
}


com.tchManage.servlet.PostController.java
//查找所有公告
private void findAll(HttpServletRequest request,
HttpServletResponse response) {
try{
//request.setAttribute("pageinfo",postdao.pageSize());
//String currpage=request.getParameter("currentPage");

int currentPage=1;
//if(currpage!=null){
// currentPage=Integer.parseInt(currpage);
//}
List<Post> list = new ArrayList<Post>();
list = postdao.findAllPost(currentPage);
request.setAttribute