Solved

java.lang.NumberFormatException

Posted on 2008-06-10
5
723 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 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Protect jar file - windows app 2 38
Application launch issue with Apache Tomcat 5 19
Show banners that are blocked by Ad Muncher 10 44
oracle 11g 23 47
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
The viewer will learn how to count occurrences of each item in an array.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

914 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now