• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Getting NullPointerException while uploading a file

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In my project,in the production some how we are getting NullPointerException while uploading a file. To upload a file we are using <html:file property=""> struts tag and we are using FormFile as the property of the form. We are trying to simulate this issue in the local by using Chrome,internet explorer,safari,Opera and mozila. we are unable to simulate, but in production we are getting NullPointerException while getting the form property like below

public class MyForm
{
private FormFile myFile;
setter & getter
}

In Action we are saying

myForm.getMyFile().getFileName();

Here we are getting NullPointerException.


if we don't upload any file, in action for the "myForm.getMyFile()" its giving empty. But some how in some cases we are getting for the same(myForm.getMyFile()) null. we are thinking that some browsers are not supporting file upload. Can you help me. Its urgent Please
 
Marshal
Posts: 79239
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Either myForm is null, or the getMyFile() method of myForm is returning null.
 
Campbell Ritchie
Marshal
Posts: 79239
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

venu babu Karri wrote: . . . Its urgent Please

There's no such thing as urgent here.
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Moving to Struts.
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No browser doesn't support file upload. (Although you should be checking for null--what if they *meant* to not upload a file? I don't recall what Struts 1 does under that circumstance.)

You need to figure out what's different between the requests that succeed and those that fail.
 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi venu babu Karri ,

if struts 2
do the following
in action tag in struts.xml make sure you do this

Then in your struts file tag please set the name attribute to myFile

In action class please do the following

this will help
Apache fileupload
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
FormFile is a Strits 1 artifact.
 
venu babu Karri
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:Either myForm is null, or the getMyFile() method of myForm is returning null.






getMyFile() is null. Then how it is becoming null.. I am unable to know. Generally while using <html:file> and FormFile to upload a file, If we dont upload a file getFormFile() gives empty string,If we upload some thing getFormFile() gives file name what we have uploaded. In some case getFormFile() is returning null.If you know.. Please let me know
reply
    Bookmark Topic Watch Topic
  • New Topic