While I thought of setting array list value to array list bean it is returning null pointer exception.
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”
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
DailysheetFormclass object is not created by framework.reasons are you din’t configure
FormBeanclass andActionclass are properly instruts-config.xmlFirst you should check what page(which data ?) is submitted to action class ie
check this line you are type casting
formintoDailysheetFormtype object then framework automatically call the setter methods ofDailysheetFormaction form so maybe here you are gettingNullPointerExceptioni think so check it..and One more thing you have to check in
struts-config.xmlentriesi.e in
<action> tab name attribute valuemust be match with<form-beans>mappingscheck the package names also…