inputFileUpload error

C

canodabasioglu

I created FileUploadForm.java as a managed bean in my application which

I call
from my upload form copied from UploadForm.jsp - when I click the
'upload' button I get this error:

java.lang.NullPointerException at
com.odabasioglu.master.backbean.FileUploadForm.processMyFile

Any help is greatly appreciated, thanks in advance...

Can ODABAÞIOÐLU




UploadForm.jsp******************
<h:form id="MyForm" enctype="multipart/form-data">
<x:inputFileUpload id="fileUpload" value="#{FileUploadForm.myFile}"
storage="file" required="true"/>
<h:commandButton value="Submit"
action="#{FileUploadForm.processMyFile}"/>
</h:form>


FileUploadForm.java***************
private UploadedFile myFile;
private String myParam;
private String myResult;


public UploadedFile getMyFile() {
return myFile;
}


public void setMyFile(UploadedFile myFile) {
this.myFile = myFile;
}
public String processMyFile() {


InputStream in = new
BufferedInputStream(file.getInputStream());
}
web.xml****************
<filter>
<filter-name>ExtensionsFilter</filter-name>
<filter-class>
org.apache.myfaces.component.html.util.ExtensionsFilter
</filter-class>
<init-param>
<param-name>uploadMaxFileSize</param-name>
<param-value>10m</param-value>
</init-param>
<init-param>
<param-name>uploadThresholdSize</param-name>
<param-value>100k</param-value>
</init-param>
</filter>


<filter-mapping>
<filter-name>ExtensionsFilter</filter-name>
<servlet-name>FacesServlet</servlet-name>
</filter-mapping>
 
L

Lew

I created FileUploadForm.java as a managed bean in my application which

I call
from my upload form copied from UploadForm.jsp - when I click the
'upload' button I get this error:

java.lang.NullPointerException at
com.odabasioglu.master.backbean.FileUploadForm.processMyFile

In general, take a look at the line or method identified in the exception, and
see what possibly *could* be null, debug to find out if it actually is null at
the point of invocation, and suss out why it was never set non-null.

How many variables are there at the point identified? Which ones could be null?

FileUploadForm.java***************

Slightly incomplete example.
private UploadedFile myFile;
private String myParam;
private String myResult;


public UploadedFile getMyFile() {
return myFile;
}


public void setMyFile(UploadedFile myFile) {
this.myFile = myFile;
}
public String processMyFile() {


InputStream in = new
BufferedInputStream(file.getInputStream());
}

Where is the variable 'file' declared?
Where is it (supposed to be) set to a non-null value?

- Lew
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,022
Latest member
MaybelleMa

Latest Threads

Top