我是一个真正的 NOOB 和新编码员。我开始学习 Java,最近在 eclipse 上创建了这个应用程序。它是美元对欧元的转换器。每次我尝试在 Eclipse 上运行代码时,我都会收到错误消息,说应用程序已停止工作。
TextView dollars;
TextView euros;
RadioButton dtoe;
RadioButton etod;
Button calculate;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
dollars = (TextView)this.findViewById(R.id.dollars);
euros = (TextView)this.findViewById(R.id.euros);
dtoe = (RadioButton)this.findViewById(R.id.dtoe);
etod = (RadioButton)this.findViewById(R.id.euros);
calculate = (Button)this.findViewById(R.id.calculate);
calculate.setOnClickListener(this);
}
public void onClick(View v) {
if (dtoe.isChecked()){
convertDollarsToEuros();
}
if (etod.isChecked()){
convertEurosToDollars();
}
}
protected void convertDollarsToEuros(){
double val = Double.parseDouble(dollars.getText().toString());
euros.setText(Double.toString(val*0.67));
}
protected void convertEurosToDollars(){
double val = Double.parseDouble(euros.getText().toString());
dollars.setText(Double.toString(val*0.67));
}
}