[问题] 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