美好的一天。我在eclipse中爲android編寫應用程序,當EditText爲空時,應用程序崩潰。我嘗試了很多方法,但不起作用。當我輸入它並且EditText是emty時,它每當它崩潰。對不起我的英語不好。 這是我的部分代碼:eclipse - 當EditText爲空時android應用程序崩潰
public class MainActivity extends Activity implements OnClickListener {
TextView mnozstvo;
TextView percento;
TextView hmotnost;
TextView vysledok1;
TextView vysledok2;
TextView text;
RadioButton muz1;
RadioButton zena1;
Button vysledok;
EditText coo;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
text = (TextView)this.findViewById(R.id.text);
mnozstvo = (TextView)this.findViewById(R.id.dl);
percento = (TextView)this.findViewById(R.id.per);
hmotnost = (TextView)this.findViewById(R.id.kg);
vysledok1 = (TextView)this.findViewById(R.id.krv);
vysledok2 = (TextView)this.findViewById(R.id.dych);
muz1 = (RadioButton)this.findViewById(R.id.muz);
zena1 = (RadioButton)this.findViewById(R.id.zena);
vysledok = (Button)this.findViewById(R.id.vysledok);
vysledok.setOnClickListener(this);
}
.................
public void convertDollarsToEuros() {
double val = Double.parseDouble(mnozstvo.getText().toString());
double val1 = Double.parseDouble(percento.getText().toString());
double val2 = Double.parseDouble(hmotnost.getText().toString());
vysledok1.setText(Double.toString((val*val1*0.8)/(val2*0.68)));
vysledok2.setText(Double.toString(((val*val1*0.8)/(val2*0.68))/(2.1)));
text.setText(Double.toString(((val*val1*0.8)/(val2*0.68))*6.6164));
}
public void convertEurosToDollars() {
double val = Double.parseDouble(mnozstvo.getText().toString());
double val1 = Double.parseDouble(percento.getText().toString());
double val2 = Double.parseDouble(hmotnost.getText().toString());
vysledok1.setText(Double.toString((val*val1*0.8)/(val2*0.55)));
vysledok2.setText(Double.toString(((val*val1*0.8)/(val2*0.55))/(2.1)));
text.setText(Double.toString(((val*val1*0.8)/(val2*0.55))*6.6164));
有人可以幫助我嗎?
請發表任何崩潰的完整堆棧跟蹤幫助。 – 2013-02-21 20:48:30