I want to make an calculate the outside its two-digit division that the user use edit box to input the two numbers and when the user leave one edit text empty he git an error messages without crushing the app i tried to it but the app always crush
public class MainActivity extends AppCompatActivity {
private EditText a1,a2;
private Button s;
private TextView d;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate( savedInstanceState );
setContentView( R.layout.activity_main );
a1=findViewById( R.id.editTextTextPersonName );
a2=findViewById( R.id.editTextTextPersonName2 );
s=findViewById( R.id.button );
d=findViewById( R.id.textView );
s.setOnClickListener( new View.OnClickListener() {
@Override
public void onClick(View view) {
float aa = Float.parseFloat( a1.getText().toString() );
float ss = Float.parseFloat( a2.getText().toString() );
float f = aa / ss;
if(a1.getText().toString()==null){
a1.setError( "n1 is required" );
a1.requestFocus();
}else if(a2.getText().toString()==null){
a2.setError( "n1 is required" );
a2.requestFocus();
}else {
d.setText( (int) f );
}
}
});
}
}