title: How can I remove NullPointerException in Struts1.x
body: <p>I am new to STRUTS and am trying to work out simple example . When I execute the example I get the following error on the internet browser..</p>
  
  <pre><code>&lt;&lt; javax.servlet.ServletException: javax.servlet.jsp.JspException: Exception creating bean of class com.example.LoginForm &gt;&gt;
  </code></pre>
  
  <p>and in the Eclipse console see a similar error with additional line on Null pointer exception</p>
  
  <pre><code>&lt;&lt; SEVERE: Error creating form bean of class com.example.LoginForm
  java.lang.NullPointerException &gt;&gt;
  </code></pre>
  
  <p>Listed below is part of my <code>struts-config.xml</code></p>
  
  <h1>struts-config.xml - Extract</h1>
  
  <pre><code>&lt;struts-config&gt;
  
  &lt; form-beans&gt;   
    &lt; form-bean name="loginRequest" type="com.example.LoginForm" /&gt;    
  &lt;/form-bean&gt;
  &lt; /form-beans&gt;
  
  
  &lt; !-- =========================================== Global Forward Definitions --&gt;
  
  &lt; global-forwards&gt;  
  &lt; forward
     name="welcome"
     path="/Welcome.do"/&gt;  
  &lt; /global-forwards&gt;
  
  
  &lt; !-- =========================================== Action Mapping Definitions --&gt;
  
  &lt; action-mappings&gt;   
  &lt; action path="/login"
      name="loginRequest"
      type="com.example.LoginAction"&gt;   
   &lt; forward name="success"
       path="/success.jsp"&gt;
   &lt; /forward&gt;    
   &lt; forward name="failure"
       path="/login.jsp"&gt;
    &lt; /forward&gt;
   &lt;/action&gt;    
   &lt;action path="/Welcome"
      forward="/pages/Welcome.jsp"/&gt;
  &lt; /action-mappings&gt;
  
  
  &lt; !-- ======================================== Message Resources Definitions --&gt;
  
  &lt; message-resources parameter="MessageResources" /&gt;
  
  &lt; /struts-config&gt;    
  </code></pre>
  
  <h1>My JSP login.jsp</h1>
  
  <pre><code>&lt; %@ taglib prefix="bean" uri="/WEB-INF/struts-bean.tld" %&gt;    
  &lt; %@ taglib prefix="html" uri="/WEB-INF/struts-html.tld" %&gt;
  
  &lt; bean:message key="title" /&gt;
  
  &lt; html:form action="login"&gt;
  
      &lt;bean:message key="login.username"/&gt;
  
      &lt;html:text property="username"&gt;&lt;/html:text&gt;
  
      &lt;br&gt;
  
      &lt;bean:message key="login.password"/&gt;
  
      &lt;html:text property="password"&gt;&lt;/html:text&gt;
  
      &lt;br&gt;
  
      &lt;html:submit&gt;
          &lt;bean:message key="login.submit"/&gt;
      &lt;/html:submit&gt;
  
  &lt; /html:form&gt;
  </code></pre>
  
  <h1>The LoginForm class</h1>
  
  <pre><code>package com.example;
  
  import org.apache.struts.action.ActionForm;
  
  public class LoginForm extends ActionForm     
  {     
      private String username;   
      private String password;
  
      public LoginForm()
      {
  
      }
  
      public String getUsername() {
          return username;
      }
      public void setUsername(String username) {
          this.username = username;
      }
      public String getPassword() {
          return password;
      }
      public void setPassword(String password) {
          this.password = password;
      }
  
  }
  </code></pre>
  
  <h1>The LoginAction class</h1>
  
  <pre><code>package com.example;   
  
  import javax.servlet.http.HttpServletRequest;    
  import javax.servlet.http.HttpServletResponse;     
  
  import org.apache.struts.action.Action;     
  import org.apache.struts.action.ActionForm;     
  import org.apache.struts.action.ActionForward;      
  import org.apache.struts.action.ActionMapping;     
  
  public class LoginAction extends Action   
  {     
      @Override    
      public ActionForward execute(ActionMapping mapping, ActionForm form,    
              HttpServletRequest request, HttpServletResponse response)    
              throws Exception     
      {   
          LoginForm login = (LoginForm)form;     
          String name = login.getUsername();    
          String pass = login.getPassword();    
  
          if(name.equals("hello") &amp;&amp; pass.equals("hello"))    
              return mapping.findForward("success");   
          else    
              return mapping.findForward("failure");    
      }    
  }   
  </code></pre>
  
  <h1>The MessageResources.properties class</h1>
  
  <pre><code>title=Welcome   
  login.username=Username    
  loguin.password=Password    
  login.submit=Submit
  </code></pre>
  
  <h1>Stack Trace</h1>
  
  <pre><code>org.apache.struts.util.RequestUtils createActionForm    
  SEVERE: Error creating form bean of class com.example.LoginForm 
  java.lang.NullPointerException
  =========== ======================
      at org.apache.struts.config.FormBeanConfig.createActionForm(FormBeanConfig.java:289)
      at org.apache.struts.util.RequestUtils.createActionForm(RequestUtils.java:259)
      at org.apache.struts.util.RequestUtils.createActionForm(RequestUtils.java:213)
      at org.apache.struts.taglib.html.FormTag.initFormBean(FormTag.java:526)
      at org.apache.struts.taglib.html.FormTag.doStartTag(FormTag.java:503)
      at org.apache.jsp.login_jsp._jspx_meth_html_005fform_005f0(login_jsp.java:122)
      at org.apache.jsp.login_jsp._jspService(login_jsp.java:79)
      at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
      at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374)
      at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
      at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
      at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:849)
      at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
      at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:454)
      at java.lang.Thread.run(Unknown Source)
  
  Jun 23, 2011 12:56:47 PM org.apache.struts.util.PropertyMessageResources loadLocale
  WARNING:   Resource org/apache/struts/taglib/html/LocalStrings_en_US.properties Not Found.
  Jun 23, 2011 12:56:47 PM org.apache.struts.util.PropertyMessageResources loadLocale
  WARNING:   Resource org/apache/struts/taglib/html/LocalStrings_en.properties Not Found.
  Jun 23, 2011 12:56:47 PM org.apache.catalina.core.StandardWrapperValve invoke
  SEVERE: Servlet.service() for servlet jsp threw exception &lt;br/&gt;&lt;br/&gt;
  javax.servlet.jsp.JspException: Exception creating bean of class com.example.LoginForm under form name loginRequest
      at org.apache.struts.taglib.html.FormTag.initFormBean(FormTag.java:536)
      at org.apache.struts.taglib.html.FormTag.doStartTag(FormTag.java:503)
      at org.apache.jsp.login_jsp._jspx_meth_html_005fform_005f0(login_jsp.java:122)
      at org.apache.jsp.login_jsp._jspService(login_jsp.java:79)
      at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
      at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374)
      at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
      at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
      at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:849)
      at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
      at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:454)
      at java.lang.Thread.run(Unknown Source)
  </code></pre>
  
  <p>Can anyone figure out what I am doing wrong and why this error is occuring.</p>
  
  <p>Thanks,<br>
  Ankit</p>