title: Struts has detected an unhandled exception: java.lang.NullPointerException
body: <p>Hi I have this problem whit my code, i tried upload file to server and keep on database.</p>
  
  <p>The first version was the same code without fileupload, and all worked good.</p>
  
  <p>struts.xml</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;action name="Crear" class="actions.AccionAnadirCliente"&gt;
      &lt;interceptor-ref name="fileUpload"&gt;
          &lt;param name="maximunSize"&gt;1048576&lt;/param&gt;
          &lt;param name="allowedTypes"&gt;image/png,image/gif,image/jpg,image/jpeg&lt;/param&gt;
      &lt;/interceptor-ref&gt;  
      &lt;result name="input"&gt;/paginaBienvenida.jsp&lt;/result&gt;
      &lt;result name="success"&gt;/nuevoCliente.jsp&lt;/result&gt;
  &lt;/action&gt;
  </code></pre>
  
  <p>now, the execute on accionAnadirCliente</p>
  
  <pre><code>public String execute() throws Exception {
      String filePath = "C:\\Users\\alumno\\Desktop\\DWES_JAVA\\imagenes";
      //crea un fichero
      File fileToCreate = new File(filePath, this.fileFileName);
      String rutaCompleta=filePath+ this.fileFileName;
      //volcado de datos.
      FileUtils.copyFile(this.file, fileToCreate);
  
  
      Cliente cliente = new Cliente();
      System.out.println(getNombre());
  
      cliente.setNombre(getNombre()); 
      cliente.setEdad(getEdad());
      cliente.setEmail(getEmail());
      cliente.setTelefono(getTelefono()); 
      cliente.setRuta(rutaCompleta);
  
      InterfaceClienteDAO clienteDAO = FactoriaDAO.getAlumnoDAO("MySQL");
  
      clienteDAO.insertarCliente(cliente);    
  
      return SUCCESS;
  
  }
  </code></pre>
  
  <p>bean Cliente</p>
  
  <pre><code>private String nombre;
  private String email;
  private String telefono;
  private int edad;
  private String ruta;
  </code></pre>
  
  <p>and getters and setters.</p>
  
  <p>ClienteDAO</p>
  
  <pre><code>public void insertarCliente(Cliente c){
  
      try {
          db.abrirConexion();
          String query = "insert into cliente values('" + c.getNombre() + "','"
                  + c.getEmail() + "','" + c.getTelefono() + "',"
                  + c.getEdad() + ","+c.getRuta()+" )";
          db.ejecutarUpdate(query);
          db.commit();
          db.cerrarConexion();
  
      } catch (Exception e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
  }
  </code></pre>
  
  <p>nuevoCliente.jsp  only contains information.</p>
  
  <p>Now the exception.</p>
  
  <pre><code>Struts Problem Report
  
  Struts has detected an unhandled exception:
  
  Messages:   
  Stacktraces
  
  java.lang.NullPointerException
      java.io.File.(Unknown Source)
      actions.AccionAnadirCliente.execute(AccionAnadirCliente.java:38)
      sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
      sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
      java.lang.reflect.Method.invoke(Unknown Source)
      com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:450)
      com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:289)
      com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:252)
      org.apache.struts2.interceptor.FileUploadInterceptor.intercept(FileUploadInterceptor.java:325)
      com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
      org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:54)
      org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:562)
      org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77)
      org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:99)
      org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
      org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
      org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
      org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
      org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
      org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
      org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
      org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
      org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
      org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
      org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1023)
      org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
      org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
      java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
      java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
      java.lang.Thread.run(Unknown Source)
  </code></pre>
  
  <p>thanks, Ivan.</p>
  
  <p>edit: 
  the exception line is this</p>
  
  <pre><code>File fileToCreate = new File(filePath, this.fileFileName);
  </code></pre>