<%
List listSonBoard =(List)mapboard.get(new Integer(mainBoard.getBoardId()));
for(int j=0;j<listSonBoard.size();j++) //java.lang.NullPointerException
{
Board sonBoard=(Board)listSonBoard.get(j);
Topic topic =new Topic();
User user=new User();
int boardId =sonBoard.getBoardId();
List listTopic=new TopicDAO().findListTopic(1, boardId);
if(listTopic!=null&&listTopic.size()>0)
{
//取得最後發表的帖子
topic=(Topic)listTopic.get(0);
user=new UserDAO().findById(topic.getuId());
}
%>
上面 for(int j=0;j<listSonBoard.size();j++) 出現 //java.lang.NullPointerException
加了判斷
if(listSonBoard != null){
for(.....){ ..... }
}
有部分可以在 mainBoard.getBoardId()<=3 時顯示的 ,不可以顯示了.
List listSonBoard =(List)mapboard.get(new Integer(mainBoard.getBoardId()));
if(listSonBoard!=null){//這句話加上肯定是對的,對,“mainBoard.getBoardId()<=3 時顯示的 ,不可以顯示了.”肯定沒影響,看看是不是其他原因導致不顯示。
for(int j=0;j<listSonBoard.size();j++) //java.lang.NullPointerException
{
Board sonBoard=(Board)listSonBoard.get(j);
Topic topic =new Topic();
User user=new User();
int boardId =sonBoard.getBoardId();
List listTopic=new TopicDAO().findListTopic(1, boardId);
if(listTopic!=null&&listTopic.size()>0)
{
//取得最後發表的帖子
topic=(Topic)listTopic.get(0);
user=new UserDAO().findById(topic.getuId());
}
}