[問題] Android問題求解

作者: k6870 (WTF)   2018-08-13 00:53:23
要做一個華氏攝氏轉換的APP
以下是程式碼,編譯後沒有錯誤,但一執行就崩潰
請大大指點Orz
public class Temp extends AppCompatActivity
implements RadioGroup.OnCheckedChangeListener,TextWatcher
{
RadioGroup unit; //單選鈕群組
EditText txv; //輸入欄
TextView tx1; //文字方塊
TextView tx2; //文字方塊
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_temp);
unit = (RadioGroup)findViewById(R.id.unit);
unit.setOnCheckedChangeListener(this);
EditText txv = (EditText) findViewById(R.id.txv);
txv.addTextChangedListener(this);
RadioGroup unit = (RadioGroup) findViewById(R.id.unit);
TextView tx1 = (TextView) findViewById(R.id.tx1);
TextView tx2 = (TextView) findViewById(R.id.tx2);
}
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i1,
int i2) { }
@Override
public void onTextChanged(CharSequence charSequence, int i, int i1, int
i2) { }
@Override
public void afterTextChanged(Editable editable) { calc(); }
@Override
public void onCheckedChanged(RadioGroup radioGroup, int i) { calc(); }
protected void calc() {
double c, f,x;
int d;
String str = txv.getText().toString();
try {
x = Double.parseDouble(str);
} catch (Exception e) {
x = 0;
}
if (unit.getCheckedRadioButtonId() == R.id.F) {
f = x;
c = (f - 32) * 5 / 9;
} else {
c = x;
f = c * 9 / 5 + 32;
}
tx1.setText(String.format("%.1f", f));
tx2.setText(String.format("%.1f", c));
作者: Expsun (無限燃燒)   2018-08-13 07:26:00
錯誤訊息呢?

Links booklink

Contact Us: admin [ a t ] ucptt.com