我犯了這段代碼,當我嘗試將可編輯的值轉換爲整數時,程序崩潰了,因爲它的文本類型是十進制的,我懷疑它是在應用程序必須將可編輯字符串更改爲字符串由於在編輯文本時編輯文本爲空時事實崩潰。可編輯的字符串崩潰
EditText Y = (EditText) findViewById(R.id.y);
Y.addTextChangedListener(new TextWatcher(){
@Override
public void afterTextChanged(Editable s) {
if(s != null){
int Yvalue = Integer.parseInt(s.toString());
}
}
'Y'爲空或'Integer.parseInt'失敗 – Blackbelt
發佈logcat錯誤。 –
也許使用try-catch?嘗試{ \t \t \t int Yvalue = Integer.parseInt(s); \t \t}趕上(例外五){ \t \t \t //無法解析 \t \t} –