Ich mache eine App, die alles, was ich brauche, mit nur einem Klick auf eine Schaltfläche berechnen kann, aber das erzwungene Schließen, wenn ich die Schaltfläche "Berechnen" drücke, kann mir jemand mit was ich helfen falsch gemacht?Berechne alles mit einer Taste
previous = (EditText) findViewById(R.id.editText);
present = (EditText) findViewById(R.id.editText2);
Button calculate = (Button) findViewById(R.id.calculate);
consumption = (TextView) findViewById(R.id.textView1);
basic = (TextView) findViewById(R.id.textView2);
mmp = (TextView) findViewById(R.id.textView3);
stp = (TextView) findViewById(R.id.textView4);
before = (TextView) findViewById(R.id.textView5);
penalty = (TextView) findViewById(R.id.textView6);
after = (TextView) findViewById(R.id.textView7);
calculate.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
makeCalculations();
}
});
}
private void makeCalculations() {
double n1 = Double.valueOf(previous.getText().toString());
double n2 = Double.valueOf(present.getText().toString());
double n3 = Double.valueOf(consumption.getText().toString());
double n4 = Double.valueOf(stp.getText().toString());
double n5 = Double.valueOf(mmp.getText().toString());
double n6 = Double.valueOf(penalty.getText().toString());
double n7 = Double.valueOf(before.getText().toString());
double n8 = Double.valueOf(basic.getText().toString());
consumption.setText("Your Consumption is: " + (n1 + n2));
basic.setText("Your Consumption is: " + (n3 * 280.00));
mmp.setText("Meter Maintenance Fee: " + 10.00);
stp.setText("Septage Fee: " + (n3 * 0.068));
before.setText("On/Before Due Date: " + (n3 + n4 + n5));
penalty.setText("Penalty: " + (n3/10.00));
after.setText("After Due Date: " + (n6 + n7));
}
}
Können Sie Ihr Fehlerprotokoll posten? –
E/Test: Ausnahme E/Android Runtime: schwerwiegendes EXCEPTION: main java.lang.NumberFormatException: Ungültige Doppel: "" bei java.lang.StringToReal.invalidReal (StringToReal.java:63) bei java.lang.StringToReal .parseDouble (StringToReal.java:248) bei java.lang.Double.parseDouble (Double.java:295) – mikazuki
bei java.lang.Double.valueOf (Double.java:332) bei tutorialspoint.example.com.myapplication .MainActivity.makeCalculations (MainActivity.java:55) bei tutorialspoint.example.com.myapplication.MainActivity.access $ 000 (MainActivity.java:10) bei tutorialspoint.example.com.myapplication.MainActivity $ 1.onClick (MainActivity.java : 47) bei android.view.Vie w.performClick (View.java:4293) – mikazuki