I have created edittexts in which user can enter numbers. In my app user can submit the values by clicking on submit button.(Note: Initially I set all 3 EditTexts to “” with setText() in the code)After submitting I have kept these following lines to retrieve values in the method.
String st1=editText1.getText().toString();
int tempVal1=Integer.parseInt(st);
String st2=editText2.getText().toString();
int tempVa2=Integer.parseInt(st);
String st3=editText2.getText().toString();
int tempVal3=Integer.parseInt(st);
But here my problem is if the user doesn’t enter any value in the first editText and fills only 2nd and 3rd and submits, then the value in the tempVal1 should be 0. But I am getting exception becuase of the first statement because of not having any data. How to avoid this exception and keep the tempVal 0 when he doesn’t fill anything in the respective edittext?
I have one more doubt, when I add this int x=Integer.valueOf(editText.getText()); line, I am getting the following error. Why?The method valueOf(String) in the type Integer is not applicable for the arguments (Editable)
Please clarify my doubts.
You need to check the
EditTextbefore converting it into Number.