当前位置: 代码迷 >> Java Web开发 >> [求助]为什么出现NullPointerException
  详细解决方案

[求助]为什么出现NullPointerException

热度:534   发布时间:2006-10-25 13:28:39.0
[求助]为什么出现NullPointerException

我是用STRUTS写的一个从数据库中取出数据在页面显示的例子
第一个是javabean:

代码如下:
package bbs.domain;

public class Bbs{
private int id;
private String bbsname;
private String lasttop;
private String lastaut;
private String master;
private int today;
private int topicnumber;
private int postnumber;

public void setId(int id){
this.id = id;
}
public int getId(){
return id;
}
public void setBbsname(String bbsname){
this.bbsname = bbsname;
}
public String getBbsname(){
return bbsname;
}
public void setLasttop(String lasttop){
this.lasttop = lasttop;
}
public String getLasttop(){
return lasttop;
}
public void setLastaut(String lastaut){
this.lastaut = lastaut;
}
public String getLastaut(){
return lastaut;
}
public void setMaster(String master){
this.master = master;
}
public String getMaster(){
return master;
}
public void setToday(int today){
this.today = today;
}
public int getToday(){
return today;
}
public void setTopicnumber(int topicnumber){
this.topicnumber = topicnumber;
}
public int getTopicnumber(){
return topicnumber;
}
public void setPostnumber(int postnumber){
this.postnumber = postnumber;
}
public int getPostnumber(){
return postnumber;
}
}

第二个程序是一个ActionForm:

package bbs.domain;

import java.util.Vector;
import org.apache.struts.action.ActionForm;

public class BbsBean extends ActionForm{
private Vector data;
public void setData(Vector v){
this.data = v;
}
public Vector getData(){
return this.data;
}
}

第三个是Action:

package bbs.action;

/*
*描述:显示信息
*@author bluedreams
*@version 2.0
*/

import java.sql.*;
import java.util.Vector;
import javax.sql.DataSource;
import javax.servlet.http.*;
import org.apache.struts.action.*;
import bbs.domain.*;


public class BbsListAction extends Action{
public ActionForward execute(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws Exception{
BbsBean bbsBean = (BbsBean)form;
DataSource dataSource;
Connection conn = null;
ResultSet rs;
Statement stm;
try{
dataSource = getDataSource(request,"mybbs");
conn = dataSource.getConnection();
stm = conn.createStatement();
String sql ="select * from bbslist";
rs = stm.executeQuery(sql);
Vector v = new Vector();
Bbs bbs =null;
while(rs.next()){
bbs = new Bbs();
bbs.setId(rs.getInt("id"));
bbs.setBbsname(rs.getString("bbsname"));
bbs.setLasttop(rs.getString("lasttop"));
bbs.setLastaut(rs.getString("lastaut"));
bbs.setMaster(rs.getString("master"));
bbs.setToday(rs.getInt("today"));
bbs.setTopicnumber(rs.getInt("topicnumber"));
bbs.setPostnumber(rs.getInt("postnumber"));
v.add(bbs);
}
bbsBean.setData(v);
request.setAttribute("bbslist",bbsBean.getData());
}catch(Exception e){
e.printStackTrace();
}finally{
try{
if(conn!=null){
conn.close();
}
}catch(Exception e){
e.printStackTrace();
}
}
return mapping.findForward("bbslist");
}
}

错误信息显示是该行出错了
我怎么检查都感觉没错
谁来帮帮忙啊

[此贴子已经被作者于2006-10-25 13:29:23编辑过]


----------------解决方案--------------------------------------------------------
出来个人看看哇
----------------解决方案--------------------------------------------------------
偶自己解决了
没有对该FORM进行配置.......

----------------解决方案--------------------------------------------------------
  相关解决方案