简体   繁体   English

在Struts 1.3中设置arraylist时出现空指针异常

[英]Null Pointer Exception while setting arraylist in struts 1.3

While I thought of setting array list value to array list bean it is returning null pointer exception. 当我想到将数组列表值设置为数组列表bean时,它返回空指针异常。 Please check action class: 请检查动作类别:

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);
     }

and my action form is 我的行动表格是

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;

    }

When I run it I get following exception and in Tomcat log it is showing "dailyform is null" 当我运行它时,出现以下异常,并且在Tomcat日志中显示“ dailyform为null”

type Exception report 类型例外报告

message 信息

description The server encountered an internal error () that prevented it from fulfilling this request. 描述服务器遇到内部错误(),导致服务器无法满足此请求。

exception 例外

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.

I am not able to find the reason. 我找不到原因。 Please help to solve it and please state the reason. 请帮助解决该问题,并说明原因。

Problem is DailysheetForm class object is not created by framework. 问题是DailysheetForm类对象不是由框架创建的。

reasons are you din't configure FormBean class and Action class are properly in struts-config.xml 原因是您未在struts-config.xml中正确配置FormBean类和Action

First you should check what page(which data ?) is submitted to action class ie 首先,您应该检查哪些页面(哪些数据?)被提交给动作类,即

DailysheetForm dailyform = (DailysheetForm) form; 

check this line you are type casting form into DailysheetForm type object then framework automatically call the setter methods of DailysheetForm action form so maybe here you are getting NullPointerException i think so check it.. 检查这一行,您是将form类型转换为DailysheetForm类型对象,然后框架会自动调用DailysheetForm操作表单的setter方法,所以也许在这里您正在获取NullPointerException我想检查一下。

and One more thing you have to check in struts-config.xml entries ie in <action> tab name attribute value must be match with <form-beans> mappings check the package names also... 还有另一件事,您必须检入struts-config.xml条目,即在<action> tab name attribute value必须与<form-beans>映射匹配还要检查软件包名称...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM