File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

NullPointerException in ActionForm.validate()

 
Juhan Voolaid
Ranch Hand
Posts: 179
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a strange problem and I don't know how to solve it. It is maybe because I am using ActionForm first time and doing something wrong.

The problem is that I get a NullPointerException for a String variable that is a parameter in my form-bean - Private variable in my ActionForm class, that is a POST parameter from my (html)form.

This is the ActionForm class that I am having problems with:


Here is the Exception:


I have no idea what I am doing wrong.
[ May 02, 2006: Message edited by: Juhan Voolaid ]
 
Ravi Seshu
Ranch Hand
Posts: 38
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hey better initialize variables... with some value as local vbles need to be initialized.....for boolean ... try now..

-eswar
 
Juhan Voolaid
Ranch Hand
Posts: 179
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK - this is embarrasing.
Problem was with my html/form. The Exception was caught to line:
bupdated2=notEmpty(updated2);
Where the variable "updated2" was apsent in my html/form page.

sry
 
Jason Rodrigues
Greenhorn
Posts: 21
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The reason you are getting NPE is because you havent initailzed your object
is you try to do s.length on a null object it will give you NPE . to avoid that you need to have another check to make sure if it is null and return
false . Replace this with your function and you should be good

private boolean notEmpty(String s){
boolean b=true;
if (s == null) b=false;
if(s.length()==0){ b=false;}return b;
}
 
Jason Rodrigues
Greenhorn
Posts: 21
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sorry it wont work
you will need in the function
if (s == null) return false;
else if (s.trim().length() == 0) return false
else
return true;
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic