Please would someone tell me why the following Integer.parseInt statement throws a NumberFormatException: String string = properties.getProperty("flag"); int i = Integer.parseInt(string); The value of string is "0" ("zero"). The error also occurs if string is "1". Thanks. [ March 12, 2003: Message edited by: Clive van Hilten ]
Chris Shepherd
Ranch Hand
Joined: Jun 27, 2000
Posts: 286
posted
0
hmm only things I can think of is to check the length and make sure you don't have any extra spaces in there. ALso, try printing it out to your console right before you try to parse it to be sure it really is the value you expect. My guess is that your string isn't what you think it is. You could test the parsing function by putting a known string value("0" or "1") directly into the parse method to prove that it works. It will, I'm sure, but just to test all points of failure... HTH
as chris mentioned earlier, most of the time, the problem is with the blank spaces. Try using : . The trim function of the string class will chop of any spaces in ur string. Hope this helps. 'amit
Clive van Hilten
Greenhorn
Joined: Feb 13, 2002
Posts: 18
posted
0
Thanks very much for all the replies - the problem turned out to be a blank space - the trim() method sorted it out! Clive [ March 13, 2003: Message edited by: Clive van Hilten ]