File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Struts and the fly likes NullPointerException in ActionForm.validate() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "NullPointerException in ActionForm.validate()" Watch "NullPointerException in ActionForm.validate()" New topic

NullPointerException in ActionForm.validate()

Juhan Voolaid
Ranch Hand

Joined: Nov 18, 2003
Posts: 179
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

Joined: Mar 19, 2005
Posts: 38
hey better initialize variables... with some value as local vbles need to be initialized.....for boolean ... try now..

Juhan Voolaid
Ranch Hand

Joined: Nov 18, 2003
Posts: 179
OK - this is embarrasing.
Problem was with my html/form. The Exception was caught to line:
Where the variable "updated2" was apsent in my html/form page.

Jason Rodrigues

Joined: Oct 20, 2005
Posts: 21
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

Joined: Oct 20, 2005
Posts: 21
sorry it wont work
you will need in the function
if (s == null) return false;
else if (s.trim().length() == 0) return false
return true;
I agree. Here's the link:
subject: NullPointerException in ActionForm.validate()
It's not a secret anymore!