[問題] Android問題求解消失

看板java作者時間7年前 (2018/08/13 00:53), 編輯推噓0(001)
留言1則, 1人參與, 最新討論串2/2 (看更多)
要做一個華氏攝氏轉換的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)); -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 180.217.138.252 ※ 文章網址: https://www.ptt.cc/bbs/java/M.1534092806.A.E11.html

08/13 07:26, , 1F
錯誤訊息呢?
08/13 07:26, 1F
文章代碼(AID): #1RS6O6uH (java)
文章代碼(AID): #1RS6O6uH (java)