Solved

java.lang.NumberFormatException

Posted on 2008-06-10
5
729 Views
Last Modified: 2010-08-05
I am getting the following error, what can be the cause?

type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

org.apache.jasper.JasperException: An exception occurred processing JSP page /price.jsp at line 47

44:             
45:             System.out.print("barnesAndNoblePriceString "+barnesAndNoblePriceString);
46:             if(barnesAndNoblePriceString != "Price Not Available")
47:                 barnesAndNoblePrice = Double.valueOf(barnesAndNoblePriceString);
48:             
49:       }
50:       %>


Stacktrace:
      org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:524)
      org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:435)
      org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
      org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:803)


root cause

java.lang.NumberFormatException: For input string: "Price Not Available"
      sun.misc.FloatingDecimal.readJavaFormatString(Unknown Source)
      java.lang.Double.valueOf(Unknown Source)
      org.apache.jsp.price_jsp._jspService(price_jsp.java:106)
      org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
      org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:393)
      org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
      org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
0
Comment
Question by:COMPUTER_SC_STUDENT
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
5 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 21752149
The string must contain a valid floating point value - it doesn't
0
 
LVL 86

Accepted Solution

by:
CEHJ earned 50 total points
ID: 21752172
...and that should be

if("Price Not Available".equals(barnesAndNoblePriceString) == false)

Open in new window

0
 
LVL 86

Assisted Solution

by:CEHJ
CEHJ earned 50 total points
ID: 21752187
(otherwise you're just comparing the references of each String, which is of no interest)
0
 
LVL 92

Expert Comment

by:objects
ID: 21756132
try:

46:             if(!"Price Not Available".equals(barnesAndNoblePriceString))

That'll fix your problem, and also avoid NPE's.

Might also be worth using as constant for "Price Not Available"
0
 
LVL 11

Expert Comment

by:spoxox
ID: 21757029
I'm going to guess that barnesAndNoblePriceString is either a price (represented by a String) or the String "Price Not Available".

The correct method (and reason) for comparing Strings is shown above.

Sometimes,

if(barnesAndNoblePriceString != "Price Not Available")

will work anyway, but you can't rely on it. (I assume - dangerous, I know - the run time environment might maintain only one copy of identical Strings.) If you've had this experience, then you'll have a hard time believing what's written above!

Some other tools that might be of use:

if(!"Price Not Available".equalsIgnoreCase(barnesAndNoblePriceString.trim()))

equalsIgnoreCase(String anotherString)
          Compares this String to another String, ignoring case considerations.
trim()
          Returns a copy of the string, with leading and trailing whitespace omitted.

http://java.sun.com/javase/6/docs/api/java/lang/String.html
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
TypeError jquery issues with site - CSS conflicts 3 26
help thx 6 22
Exchange OWA website Redirection 7 44
Keyup listener getting fired on initial page load 1 14
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
There’s a good reason for why it’s called a homepage – it closely resembles that of a physical house and the only real difference is that it’s online. Your website’s homepage is where people come to visit you. It’s the family room of your website wh…
The viewer will learn how to count occurrences of each item in an array.
Any person in technology especially those working for big companies should at least know about the basics of web accessibility. Believe it or not there are even laws in place that require businesses to provide such means for the disabled and aging p…

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question