3 Replies Latest reply on Mar 28, 2011 11:13 PM by Saurabh Tyagi

    getting null pointer exception during uploadFile

    Saurabh Tyagi Newbie

      Hi, i am doing some stupid mistake to upload a file using richfaces FileUpload tag. i take richfaces demo example and try to upload file. but i am getting nullPointerException  when getting "item.getData().length"   

       

      public void listener(UploadEvent event) throws Exception{


              UploadedFile uFile= new UploadedFile();

              log.debug(" isTempFile ?? "+item.isTempFile());

                        log.debug("Set File Name : "+item.getFileName());

                        uFile.setName(item.getFileName());

               uFile.setData(item.getData());

       

                        log.debug("Content Type : "+item.getContentType());

                        log.debug("File Size : "+item.getFileSize());

                        log.debug("hash Code : "+item.hashCode());

       

               uFile.setLength(item.getData().length);   //  getting null pointer exception

                        log.debug("adding file to ArrayList()");

                        files.add(uFile);

                        log.debug("Uploaded file size="+files.size());

                        uploadsAvailable--;

          } 

       

       

      and in my logs i got

       

      isTempFile ??  true

      Set File Name : temp.jpg

      Content Type : image/jpeg

      File Size : 4331

      hash Code : 30587383

       

      14:39:54,718 ERROR http-8282-1 BaseXMLFilter:227 - Exception in the filter chain

      javax.servlet.ServletException: org.apache.jasper.el.JspELException: /SparkTG.jsp(42,12) '#{fileUploadBean.listener}' java.lang.NullPointerException

                at javax.faces.webapp.FacesServlet.service(FacesServlet.java:277)

                at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)

                at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)

                at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:530)

                at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)

                at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)

                at org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:206)

                at org.ajax4jsf.webapp.BaseFilter.handleRequest(BaseFilter.java:290)

                at org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(BaseFilter.java:367)

                at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:515)

                at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)

                at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)

                at com.sparktg.web.filter.SecurityCheckFilter.doFilter(SecurityCheckFilter.java:97)

                at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)

                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:127)

                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:298)

                at org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:861)

                at org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:579)

                at org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1584)

                at java.lang.Thread.run(Unknown Source)

      Caused by: javax.faces.el.EvaluationException: org.apache.jasper.el.JspELException: /SparkTG.jsp(42,12) '#{fileUploadBean.listener}' java.lang.NullPointerException

                at org.richfaces.webapp.taglib.MethodBindingMethodExpressionAdaptor.invoke(MethodBindingMethodExpressionAdaptor.java:83)

                at org.richfaces.component.UIFileUpload.broadcast(UIFileUpload.java:190)

                at org.ajax4jsf.component.UIInclude.broadcast(UIInclude.java:170)

                at org.ajax4jsf.component.AjaxViewRoot.processEvents(AjaxViewRoot.java:329)

                at org.ajax4jsf.component.AjaxViewRoot.broadcastEventsForPhase(AjaxViewRoot.java:302)

                at org.ajax4jsf.component.AjaxViewRoot.processPhase(AjaxViewRoot.java:261)

                at org.ajax4jsf.component.AjaxViewRoot.processDecodes(AjaxViewRoot.java:417)

                at com.sun.faces.lifecycle.ApplyRequestValuesPhase.execute(ApplyRequestValuesPhase.java:78)

                at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:100)

                at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)

                at javax.faces.webapp.FacesServlet.service(FacesServlet.java:265)

                ... 24 more

      Caused by: org.apache.jasper.el.JspELException: /SparkTG.jsp(42,12) '#{fileUploadBean.listener}' java.lang.NullPointerException

                at org.apache.jasper.el.JspMethodExpression.invoke(JspMethodExpression.java:77)

                at org.richfaces.webapp.taglib.MethodBindingMethodExpressionAdaptor.invoke(MethodBindingMethodExpressionAdaptor.java:79)

                ... 34 more

       

       

      please help.

       

      Thanks & Regards

       

      Saurabh

       


        • 1. getting null pointer exception during uploadFile
          Saurabh Tyagi Newbie

          sorry i forgot to write "UploadedFile uFile= new UploadedFile();" line in to above function.

           

          public void listener(UploadEvent event) throws Exception{


                  UploadedFile uFile= new UploadedFile();

                  log.debug(" isTempFile ?? "+item.isTempFile());

                            log.debug("Set File Name : "+item.getFileName());

                            uFile.setName(item.getFileName());

                   uFile.setData(item.getData());

           

                            log.debug("Content Type : "+item.getContentType());

                            log.debug("File Size : "+item.getFileSize());

                            log.debug("hash Code : "+item.hashCode());

           

                   uFile.setLength(item.getData().length);   //  getting null pointer exception

                            log.debug("adding file to ArrayList()");

                            files.add(uFile);

                            log.debug("Uploaded file size="+files.size());

                            uploadsAvailable--;

              }

          • 2. getting null pointer exception during uploadFile
            Nick Belaevski Master

            Hi,

             

            So, has this solved the problem?

            • 3. getting null pointer exception during uploadFile
              Saurabh Tyagi Newbie

              Yes, i am able to upload file correctly. richfaces makes it so easy. Thanks RichFaces....