Skip to content Skip to sidebar Skip to footer

Invalid Double. Number Format Exception In Android

I have this in xml. So, t

Solution 1:

getText() does not return the value inside android:hint. So you are trying to convert an empty string as double. use android:text property instead.

<EditText
    android:id="@+id/creditlimitfield2"
    android:text="0"
    android:inputType="numberDecimal" />

Solution 2:

Looks like creditlimit.getText().toString() does not a return a valid double value. Make sure you enter a valid double in the EditText.

Numberformatexception. Invalid double""

Empty string is not a valid double.

Also i guess you have this just after initialization make sure you get the text from edittext on button click or in onResume

double credit_limit = Double.valueOf(creditlimit.getText().toString())

If you want the default value follow blackbelt's post.

Solution 3:

try this Sting limit=creditlimit.getText().toString(); double credit_limit =0; if(limit!=null && !limit.isEmpty()){ credit_limit = Double.parseDouble(limit); }

Post a Comment for "Invalid Double. Number Format Exception In Android"