Hello! I would like to ask for help. I'm new to Android studio and I'm trying to create an application for my physics students to calculate motion equations. One of the methods is to calculate the equation "V = v0 + at", when the editTexts are populated it works normal, but when one gets empty the application stops. I've tried in many ways to use methods that identify empty variables but it never works.
Follow the code below:
public void velocidadeTempo(View view){
setContentView(R.layout.velocidade_tempo);
final EditText editV0 = findViewById(R.id.editv0);
final EditText editA = findViewById(R.id.edita);
final EditText editT = findViewById(R.id.editt);
final TextView tvV1 = findViewById(R.id.tvResultado);
final double[] velocidadeF = new double[1];
Button btcalcular = findViewById(R.id.btCalcular);
btcalcular.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String numv0 = editV0.getText().toString();
double v0 = Double.parseDouble(numv0);
String numa = editA.getText().toString();
double a = Double.parseDouble(numa);
String numt = editT.getText().toString();
double t = Double.parseDouble(numt);
velocidadeF[0] = v0 + (a*t);
if(editV0.getText().toString().isEmpty()||editA.getText().toString().isEmpty()||editT.getText().toString().isEmpty()){
tvV1.setText("sem resposta");
}else{
tvV1.setText(velocidadeF[0]+"");
}
}
});
}
Remembering that the value "0" is valid in the equation.