public void add(View v)
{
EditText first=findViewById(R.id.first),second=findViewById(R.id.second);
double f=Double.parseDouble(first.getText().toString());
double s=Double.parseDouble(second.getText().toString());
TextView result=findViewById(R.id.result);
double r;
if(TextUtils.isEmpty(first.getText().toString()))
{
first.setError("This field can't be empty");
}
else if(TextUtils.isEmpty(second.getText().toString()))
{
second.setError("This field can't be empty");
}
else {
r = f + s;
result.setText("" + r);
}
}
I want to add two numbers from taking input from user and display an error msg if editText is empty.
But on executing this piece of code my app keeps crashing.