Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

java.lang.NullPointerException

 
Samer, qc
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
Can anyone tell me why i'm getting this error:
java.lang.NullPointerException
here is the code:

Samer
 
Sowmya Vinay
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 6920
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"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 http://www.javaranch.com/name.jsp .
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.
Thanks.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic