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

type Exception report


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


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

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


root cause

java.lang.NumberFormatException: For input string: "Price Not Available"
      sun.misc.FloatingDecimal.readJavaFormatString(Unknown Source)
      java.lang.Double.valueOf(Unknown Source)
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
LVL 86

Expert Comment

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

Accepted Solution

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

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

Open in new window

LVL 86

Assisted Solution

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

Expert Comment

ID: 21756132

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"
LVL 11

Expert Comment

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.


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.
          Returns a copy of the string, with leading and trailing whitespace omitted.

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