This week's book giveaway is in the Java in General forum.
We're giving away four copies of Think Java: How to Think Like a Computer Scientist and have Allen B. Downey & Chris Mayfield on-line!
See this thread for details.
Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Why NumberFormatException?

 
Jyoti Vaskar
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a jsp page in which I enter age.

I am getting the value from jsp into servlet by



But now while running I am getting exception of NumberFormatException

when I enter any value into text box of age and press add button of JSP.

Why is that?
Can anybody explain?
 
Rahul P Kumar
Ranch Hand
Posts: 188
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Possibly you need to trim the age string, as:

 
Rahul P Kumar
Ranch Hand
Posts: 188
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
By the way, if you had taken stack trace, you yourself had figured it out the exact reason, or could have shown to us.
 
Jyoti Vaskar
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks for the reply.

I have added trim() as you said & now its shocking

that I am getting a NullPointerException?? ??

I would like to know about stack trace.

I really don't know about it.
 
Jyoti Vaskar
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I have sort out it.
It was the mistake made in jsp page where <form> tag was placed wrongly.

thank you for the help.
 
Rahul P Kumar
Ranch Hand
Posts: 188
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
a null pointer exception shows, that no value is being passed from request.getParameter(). Another debugging method. Take in such cases. In your case it could have quickly shown that there is (no) value being passed. stack trace can be generated from inside catch block. Try searching Exception handling in google, if you are not aware of it.
 
Jyoti Vaskar
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rahul.p Kumar wrote: stack trace can be generated from inside catch block. Try searching Exception handling in google, if you are not aware of it.


I guess you are talking about try catch & finally blocks?

Or it may be System.out.println() about which I am aware of.

I guess stack trace is one & the same thing above, which I am aware of ?

By searching exception handeling I got the same result above !

 
Rahul P Kumar
Ranch Hand
Posts: 188
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes both are pointing to same thing. you print stack trace in catch block. These are common debugging ways, you can use to quickly blame a piece of code
 
Jyoti Vaskar
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rahul.p Kumar wrote:yes both are pointing to same thing. you print stack trace in catch block. These are common debugging ways, you can use to quickly blame a piece of code


Then I am aware of stack trace.

thank you Rahul for the help .
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic