Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java.lang.NumberFormatException: For input string: " "

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.

like image 600
razshan Avatar asked Jan 20 '23 02:01

razshan


1 Answers

I'm assuming that dataValues_fluid[] is an array of Strings. 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.

like image 55
Kevin Lacquement Avatar answered Feb 01 '23 14:02

Kevin Lacquement