• 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

NullPointerException in ActionForm.validate()

 
Ranch Hand
Posts: 179
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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;
reply
    Bookmark Topic Watch Topic
  • New Topic