I am trying to parse a double from an edittext but i keep getting a number format exception error.
i initially tried this…
premiumvalue = Double.parseDouble(premium.getText().toString());
amountweightvalue = Double.parseDouble(amountweight.getText().toString());
Then attempted this…to no avail.
try{
premiumvalue = Double.parseDouble(premium.getText().toString());
} catch (final NumberFormatException e) {
premiumvalue = 0;
}
try{
amountweightvalue = Double.parseDouble(amountweight.getText().toString());
} catch (final NumberFormatException e) {
premiumvalue = 0;
}
I’m a noob and any help fixing this would be greatly appreciated.
I have test your code test your code myself and find the following possibility to find
NumberFormatException:EditTextvalue is blank,So apply condition for EditText blank value.EditTextvalue is only dot(.),So apply condition for EditText dot value.in your comment you are saying that you are using this
so my point is that
premiumandamountweightEditText and then parse string to double??android:inputType="numberDecimal"attribute for EditText then EditText only accept 0-9 and . value.android:inputType="numberDecimal"attribute.nullcondition becauseEditTextnever returnnullvalue.I have test your code lot of way and do not find
NumberFormatExceptionif i follow above points.