When converting a String to an int using the following code, I get the error
Exception in thread "main" java.lang.NumberFormatException: For input string: "null1"
Here is the code (well, the line the error occurs):
int numbProgram=
Math.abs(Integer.parseInt(standardProgramResult) - output[0])
+ Math.abs(Integer.parseInt(standardProgramResult) - output[1])
+ Math.abs(Integer.parseInt(standardProgramResult) - output[2])
+ Math.abs(Integer.parseInt(standardProgramResult) - output[3])
+ Math.abs(Integer.parseInt(standardProgramResult) - output[4])
+ Math.abs(Integer.parseInt(standardProgramResult) - output[5])
+ Math.abs(Integer.parseInt(standardProgramResult) - output[6])
+ Math.abs(Integer.parseInt(standardProgramResult) - output[7]);
So what does null1 mean? Shouldn't that just mean 1 because null means nothing? And also, how can I fix this?
Thanks
null1and notnull? Anyway to get better help post SSCCE and entire stacktrace.standardProgramResult? And why are you callingparseInt()so many times? Do you know what a for loop is?standardProgramResult.standardProgramResultis"null1"which is not proper integer and it can't be parsed tointso you are gettingNumberFormatException. If you ware expectingstandardProgramResultto have other value thannull1then problem lies in code which you are not showing us so we can't help you much. For now it looks like it was result of concatenatingnullwith numeric String (in this case"1").