我正在用EditText視圖創建一個小的calc應用程序,當用戶離開EditText視圖時導致ParseInt嘗試並解析任何內容時,運行時出現運行時異常。我讀過,我需要'嘗試'和'趕上'這個錯誤發生之前,但林不知道在哪裏以及如何做到這一點!ParseInt異常
任何意見是非常感謝!
這裏是我的代碼:
public class HandlerExamples extends Activity implements OnClickListener {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button button = (Button)findViewById(R.id.testButton);
button.setOnClickListener(this);
public void onClick(View v) {
String a,b,t;
double vis;
EditText txtbox1 = (EditText)findViewById(R.id.A);
EditText txtbox2 = (EditText)findViewById(R.id.B);
EditText txtbox3 = (EditText)findViewById(R.id.t);
TextView tv = (TextView) findViewById(R.id.Answer);
a = txtbox1.getText().toString();
b = txtbox2.getText().toString();
t = txtbox3.getText().toString();
vis = ((Integer.parseInt(a)*1) + (Integer.parseInt(b)*2))/(Double.parseDouble(t));
tv.setText(double.toString(vis));
}
}
非常感謝!
我發現我遇到了一個ParseInteger問題,這就是在運行時導致錯誤的原因。我已經適當地編輯了這個問題。謝謝! – phi16181