如果然后声明不工作和崩溃

时间:2018-03-08 13:23:02

标签: if-statement parseint action-button

试图让我的代码工作但似乎崩溃了。 谁能帮我?提前谢谢:-)

EditText HbA1c;
TextView result;
Button button;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    HbA1c = (EditText) findViewById(R.id.HbA1c);
    button = (Button) findViewById(R.id.button);
    result = (TextView) findViewById(R.id.result);
}


public void onButtonClick(View view) {
    int num = Integer.parseInt(HbA1c.getText().toString());

    if (HbA1c == 6.5) {
        result.setText("DM");
    } else {
        result.setText("not DM");
    }
}

0 个答案:

没有答案