BoardDao boardDao = new BoardDaoImpl();
Map map = boardDao.findBoard();
List list = (List)map.get(0);
for(int i=0;i<list.size();i++){
Board board = (Board)list.get(i);
out.println(board.getBoardTitle());
}
%>[/size]
链接页面的时候会出现下面的错误
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: An exception occurred processing JSP page /HTML/MyJsp.jsp at line 33
30: <table border = "1" width = "500%">
31: <%
32: List list = (List)map.get(new Integer(0));
33: for(int i=0;i<list.size();i++){
34: Board board = (Board)list.get(i);
35: out.println(board.getBoardTitle());
36: }
Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:510)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:419)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
root cause
java.lang.NullPointerException
org.apache.jsp.HTML.MyJsp_jsp._jspService(MyJsp_jsp.java:94)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:377)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
note The full stack trace of the root cause is available in the Apache Tomcat/6.0.26 logs.
9 个解决方案
#1
很明显,空指针异常啊
#2
我在java里测试的时候就没问题阿
#3
明显list是空的
#4
BoardDao boardDao = new BoardDaoImpl();
Map map = boardDao.findBoard();
if(map != null){
List list = (List)map.get(0);
if(list != null){
for(int i=0;i<list.size();i++){
Board board = (Board)list.get(i);
out.println(board.getBoardTitle());
}
}
}
#5
Map map = boardDao.findBoard();
out.println(map );
先打印出你的map看看
out.println(map );
先打印出你的map看看
#6
map应该空的,或者键为0的没有对应键值
#7
在for循环遍历list之前先判断下list.size是否大于0,大于0再循环就不会报空指针了
#8
还有刚没注意到,你的map是这样用的List list = (List)map.get(new Integer(0)); 这样是错误的。这是基础东西。map是用键值对来存放的,遍历的时候需要根据存的键来得到值。你直接get(0),是list用多了吧?
#9
终于找到原因了,原来是我的数据库列名写错了
#1
很明显,空指针异常啊
#2
我在java里测试的时候就没问题阿
#3
明显list是空的
#4
BoardDao boardDao = new BoardDaoImpl();
Map map = boardDao.findBoard();
if(map != null){
List list = (List)map.get(0);
if(list != null){
for(int i=0;i<list.size();i++){
Board board = (Board)list.get(i);
out.println(board.getBoardTitle());
}
}
}
#5
Map map = boardDao.findBoard();
out.println(map );
先打印出你的map看看
out.println(map );
先打印出你的map看看
#6
map应该空的,或者键为0的没有对应键值
#7
在for循环遍历list之前先判断下list.size是否大于0,大于0再循环就不会报空指针了
#8
还有刚没注意到,你的map是这样用的List list = (List)map.get(new Integer(0)); 这样是错误的。这是基础东西。map是用键值对来存放的,遍历的时候需要根据存的键来得到值。你直接get(0),是list用多了吧?
#9
终于找到原因了,原来是我的数据库列名写错了