File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes java.lang.NullPointerException Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "java.lang.NullPointerException" Watch "java.lang.NullPointerException" New topic


Samer, qc

Joined: Jan 16, 2001
Posts: 2
Can anyone tell me why i'm getting this error:
here is the code:

Sowmya Vinay

Joined: Feb 01, 2001
Posts: 24
From what I see in the code snippet, I find that you are accessing a form parameter from request, but you are not making sure that it exists i.e it ia non-null value. Make sure that it is not returning a null value by including this statement "if (barCodeValue!=null)" as soon as you populate the barcodeValue variable from the request and before using it anywhere else.
The rule of thumb for dealing with Null Pointer Exceptions is to make sure that you always check whether the object populated by accessing any method is null, before invoking any of its methods.
Hope this helps.
Frank Carver

Joined: Jan 07, 1999
Posts: 6920
"Samer, qc",
The Java Ranch has thousands of visitors every week, many with surprisingly similar names. To avoid confusion we have a naming convention, described at .
We require names to have at least two words, separated by a space, and strongly recommend that you use your full real name. Please choose a new name which meets the requirements.

Read about me at ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
I agree. Here's the link:
subject: java.lang.NullPointerException
It's not a secret anymore!