?
Solved

java.lang.NumberFormatException

Posted on 2008-06-10
5
Medium Priority
?
744 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
  • 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 200 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 200 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

CTAs encourage people to do something specific to show interest in your company, product or service. Keep reading to learn why CTAs should always be thought of as extremely important, albeit small, sections of websites.
Q&A with Course Creator, Mark Lassoff, on the importance of HTML5 in the career of a modern-day developer.
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
Suggested Courses
Course of the Month13 days, 20 hours left to enroll

807 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