aspose file tools*
The moose likes Java in General and the fly likes Integer parseInt exception for a valid Int !!!!!! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Integer parseInt exception for a valid Int !!!!!!" Watch "Integer parseInt exception for a valid Int !!!!!!" New topic
Author

Integer parseInt exception for a valid Int !!!!!!

jay vas
Ranch Hand

Joined: Aug 30, 2005
Posts: 407
Hi guys : I wont waste your time : The stack trace message sais it all. Of course, this exception is being
generated by a call to the Integer.parseInt method.....
And heres the complaint :

java . lang . NumberFormat Exception For input string
3
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18117
    
  39

parseInt() is choking on the quote in your string.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
jay vas
Ranch Hand

Joined: Aug 30, 2005
Posts: 407
Hi and thanks : I assumed that.... but then I tried :

intString.replaceAll("\"","") ....

And I get the SAME exception !!!
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18117
    
  39

jay vas wrote:Hi and thanks : I assumed that.... but then I tried :

intString.replaceAll("\"","") ....

And I get the SAME exception !!!



You mean .... intString = inString.replaceAll("\"", ""); .... right?

Henry
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 13875
    
  10

Are there spaces or maybe a newline character before or after the "3" in the string that you are trying to parse? Try printing the length of the string:

If the length is more than 1 character, you know that there must be some extra spaces or other invisible characters in the string besides the "3".

You can use trim() to remove leading and trailing spaces:


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Integer parseInt exception for a valid Int !!!!!!
 
Similar Threads
why JMX can not stop
void return type in JSP expression
counting algorithm
Java ranch rules roundup
WA #1.....word association