When I try to do this:
total = Integer.parseInt(dataValues_fluid[i]) + total;
It will give me an error message
java.lang.NumberFormatException: For input string: " "
Some of the values are " ". So thats why it gives me. But I tried
int total = 0;
for(int i=0; i<counter5; i++){
if(dataValues_fluid[i]==" "){dataValues_fluid[i]="0";}
total = Integer.parseInt(dataValues_fluid[i]) + total;
}
I still get the same java.lang.NumberFormatException
error.
I'm assuming that dataValues_fluid[]
is an array of String
s. If this is the case, you can't use the ==
comparison operator - you need to use if(dataValues_fluid[i].equals(" "))
.
So your parseInt()
is attempting to parse the space character, which results in your NumberFormatException
.