虽然我想将数组列表值设置为数组列表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为null”
输入例外报告
消息
description服务器遇到内部错误(),导致无法完成此请求。
例外
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.
我无法找到原因。请帮忙解决,请说明原因。
答案 0 :(得分:1)
问题是DailysheetForm
类对象不是由框架创建的。
原因是你没有配置FormBean
课程和Action
课程正确地在struts-config.xml
首先,您应该检查哪个页面(哪些数据?)已提交给操作类,即
DailysheetForm dailyform = (DailysheetForm) form;
检查此行是否在form
类型对象中输入DailysheetForm
,然后框架会自动调用DailysheetForm
操作表单的setter方法,所以也许在这里你得到NullPointerException
i这么想看看..
还有一件事需要检查struts-config.xml
个条目
即<action> tab name attribute value
必须与<form-beans>
映射匹配
检查包裹名称......