jQuery in Action, 2nd edition*
The moose likes Java in General and the fly likes Why NumberFormatException? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Why NumberFormatException?" Watch "Why NumberFormatException?" New topic
Author

Why NumberFormatException?

Jyoti Vaskar
Ranch Hand

Joined: Jun 30, 2009
Posts: 142
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?


thanks
Jyo
Rahul P Kumar
Ranch Hand

Joined: Sep 26, 2009
Posts: 188
Possibly you need to trim the age string, as:

Rahul P Kumar
Ranch Hand

Joined: Sep 26, 2009
Posts: 188
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

Joined: Jun 30, 2009
Posts: 142
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

Joined: Jun 30, 2009
Posts: 142

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

Joined: Sep 26, 2009
Posts: 188
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

Joined: Jun 30, 2009
Posts: 142
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

Joined: Sep 26, 2009
Posts: 188
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

Joined: Jun 30, 2009
Posts: 142
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 .
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Why NumberFormatException?