0

虽然我想将数组列表值设置为数组列表 bean,但它正在返回空指针异常。请检查动作类:

public ActionForward execute(ActionMapping mapping, ActionForm form,
        HttpServletRequest request, HttpServletResponse response)
        throws Exception {

    ArrayList dailysheetdata;
    DailysheetForm dailyform = (DailysheetForm) form;
    Class.forName("com.mysql.jdbc.Driver");
    Connection connect = DriverManager.getConnection("jdbc:mysql://localhost/Stonecrusher?"
                        + "user=Stonecrusher&password=xxxxxx");
    System.out.println("Connection"+connect);
    dailysheetdata = StoneCrusherData.getDailysheetData(connect);
    if(dailysheetdata==null)
        System.out.println("dailysheetdata null");
    else if(dailyform==null)
    System.out.println("dailyform null");
    else
    dailyform.setArraylist(dailysheetdata) ;//iam getting exception here
    return mapping.findForward(SUCCESS);
     }

我的行动形式是

public class DailysheetForm extends ActionForm {
    // some getter and setter methods i used

    protected ArrayList arraylist;
    public ArrayList getArraylist() {
        return arraylist;
    }

    public void setArraylist(ArrayList arraylist) {

        this.arraylist = arraylist;

    }

当我运行它时,出现以下异常,并且在 Tomcat 日志中显示“dailyform 为空”

类型异常报告

信息

描述 服务器遇到一个内部错误 () 阻止它完成这个请求。

例外

javax.servlet.ServletException: java.lang.NullPointerException
    org.apache.struts.action.RequestProcessor.processException(RequestProcessor.java:520)
    org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:427)
    org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:228)
    org.apache.struts.action.ActionServlet.process(ActionServlet.java:1913)
    org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:449)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:722)

root cause

java.lang.NullPointerException
    com.myapp.struts.DialysheetListAction.execute(DialysheetListAction.java:59)
    org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:425)
    org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:228)
    org.apache.struts.action.ActionServlet.process(ActionServlet.java:1913)
    org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:449)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
note The full stack trace of the root cause is available in the Apache Tomcat/7.0.27 logs.

我无法找到原因。请帮忙解决,并说明原因。

4

1 回答 1

1

问题是DailysheetForm类对象不是由框架创建的。

原因是你没有配置FormBean类和Action类是正确的struts-config.xml

首先你应该检查哪个页面(哪些数据?)提交给动作类,即

DailysheetForm dailyform = (DailysheetForm) form; 

检查这一行,您正在将类型转换formDailysheetForm类型对象,然后框架会自动调用DailysheetForm操作表单的 setter 方法,所以也许在这里您得到了NullPointerException我想所以检查它..

还有一件事你必须签入struts-config.xml条目,即 in<action> tab name attribute value必须与<form-beans>映射匹配,还要检查包名称......

于 2012-06-30T11:07:26.143 回答