Bharat Sankannanavar wrote:Hello friends,
I am trying to convert string to Int but i am getting exception as java.lang.NumberFormatException: For input string: ""
Code is as follows
String no=request.getParameter(itemno); // here itemno varies everytime...sometime it will be 1 and sometime it will be 2 but in string format
String itemn[]=no.split(" ");
int itemNo=Integer.parseInt(itemn[0]);
Can anyone solve this problem for me??
Thanks in advance
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
fred rosenberger wrote:You'll be amazed at how often the string isn't what you think it is...
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Campbell Ritchie wrote:That looks a nice way to avoid the Exception, but maybe sometimes the Exception is the correct thing to do.
fred rosenberger wrote:a good debugging tip would be to print out the string just before you try and convert it, to make sure it holds what you really think it holds. I'll usually put something both before and after it, to make sure I can see trailing white-space characters...something like
You'll be amazed at how often the string isn't what you think it is...
luck, db
There are no new questions, but there may be new answers.
Jeff Verdegan wrote:Print the string's length(), in case there are additional invisible characters that are screwing up the parsing...
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Winston Gutkowski wrote:
Jeff Verdegan wrote:Print the string's length(), in case there are additional invisible characters that are screwing up the parsing...
Doh! You and I (and anybody who's ever read Josh) knows that Strings are NOT substitutes for other objects.
Aren't; never have been; never will be. The problem is that they can look like another object - particularly when it comes to representing its value.
Anybody but me see the danger of "String"-based communication?
Winston
Winston Gutkowski wrote:
Jeff Verdegan wrote:Print the string's length(), in case there are additional invisible characters that are screwing up the parsing...
Doh! You and I (and anybody who's ever read Josh) knows that Strings are NOT substitutes for other objects.
Aren't; never have been; never will be. The problem is that they can look like another object - particularly when it comes to representing its value.
Anybody but me see the danger of "String"-based communication?
Winston
Jeff Verdegan wrote:You mean like storing numbers as varchar in a DB? https://coderanch.com/t/564021/java/java/Long-value-java
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Bharat Sankannanavar wrote:I am trying to remove that space but couldn't able to do that.
Joanne
Joanne Neal wrote:
Bharat Sankannanavar wrote:I am trying to remove that space but couldn't able to do that.
Have you looked at the String javadoc to see if there is a method that will do that for you ?
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime. |