虽然我想将数组列表值设置为数组列表 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.
我无法找到原因。请帮忙解决,并说明原因。