Most likely, the NullPointerException
is thrown at one of the following two lines
File fileToCreate = new File(filePath, this.userImageFileName);
FileUtils.copyFile(this.userImage, fileToCreate);
because this.userImageFileName
and/or this.userImage
is null
, if you do not upload a file.
So, try this:
if(this.userImageFileName != null && this.userImage != null){
File fileToCreate = new File(filePath, this.userImageFileName);
FileUtils.copyFile(this.userImage, fileToCreate);
}
Now, no NullPointerException
should occure, since you checked for null
in advance.