Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
jay vas
Ranch Hand
Posts: 407
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Pie
Posts: 22107
88
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
parseInt() is choking on the quote in your string.

Henry
 
jay vas
Ranch Hand
Posts: 407
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi and thanks : I assumed that.... but then I tried :

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

And I get the SAME exception !!!
 
Henry Wong
author
Marshal
Pie
Posts: 22107
88
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15632
46
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic