The issue i’m having is that when I enter no data at all or if there is only data in one of the input boxes the program crashes but if there is any data in both boxes the program works fine so how do I stop it from sending data if nothing is entered. The error says it can parse a double of value “”
calculate.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
distanceTraveled = Double.parseDouble(distance.getText().toString());
fuelUsed = Double.parseDouble(fuel.getText().toString());
part1 = fuelUsed / 4.55;
mpg = distanceTraveled / part1;
total.setText(String.format("%.2f", mpg));
}
});
Chnage EditView for empty or null before making calculation :