首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >单击单选按钮时强制关闭

单击单选按钮时强制关闭
EN

Stack Overflow用户
提问于 2010-03-21 03:23:33
回答 2查看 345关注 0票数 1

每当我试图按下模拟器上的单选按钮时,它就会强制关闭!

代码语言:javascript
复制
public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        Button b = (Button)this.findViewById(R.id.btn_confirm);
        b.setOnClickListener(this);
        RadioButton radio_ctf = (RadioButton) findViewById(R.id.radio_ctf);
        RadioButton radio_ftc = (RadioButton) findViewById(R.id.radio_ftc);
        radio_ctf.setOnClickListener(this);
        radio_ftc.setOnClickListener(this);
    }
    @Override
    public void onClick(View v)
    {
     TextView tv = (TextView)this.findViewById(R.id.tv_result);
     EditText et = (EditText)this.findViewById(R.id.et_name);
     RadioButton radio_ctf = (RadioButton) findViewById(R.id.radio_ctf);
        RadioButton radio_ftc = (RadioButton) findViewById(R.id.radio_ftc);
     double y = 0;
     int x = Integer.parseInt(et.getText().toString());
     if(radio_ctf.isChecked())
     {
      y = ((double)x * 1.8) + 32;
     }
     if(radio_ftc.isChecked())
     {
      y = ((double)x - 32) * 0.555;
     }
     String text = "Result:" + y;
     tv.setText(text);
EN

回答 2

Stack Overflow用户

发布于 2010-03-21 04:41:48

首先,查看DDMS控制台中的错误(如果使用eclipse,则为DDMS按钮)。造成这种错误的原因很多。实际上,这意味着存在未处理java异常。

票数 2
EN

Stack Overflow用户

发布于 2010-03-21 04:43:29

我的猜测是,由于传递给Integer.parseInt()的值导致出现异常

您需要在解析字符串之前对其进行验证。

要验证该字符串,请阅读以下帖子:Java library to check whether a String contains a number exceptions

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/2484386

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档