This code must validate input data from the findActions() method:
try {
System.out.println(findActions(lookingArea.substring(0, right)));// always printing valid number string
Integer.parseInt(findActions(lookingArea.substring(0, right)));// checking for number format
}
catch(NumberFormatException exc) {
System.out.println(exc);
}
But I always have java.lang.NumberFormatException: For input string: "*number*"
that is so strange, because checking with System.out.println(findActions(lookingArea.substring(0, right)));
,
I get *number*
like 10.0
Integer.parseInt
doesn't expect the .
character. If you're sure it can be converted to an int
, then do one of the following:
".0"
off the end of the string before parsing it, orDouble.parseDouble
, and cast the result to int
.Quoting the linked Javadocs above:
The characters in the string must all be decimal digits, except that the first character may be an ASCII minus sign '-' ('\u002D') to indicate a negative value or an ASCII plus sign '+' ('\u002B') to indicate a positive value.