1

Been trying to get my code to work but it seems to comes crashing. Can anyone help me? Thank you in advance :-)

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");
    }
}
Ben Thomas
  • 3,180
  • 2
  • 20
  • 38
Louell Sala
  • 45
  • 1
  • 7
  • 2
    I think this question is quite incomplete; classical mantra is "what did you want to achieve, what you did, what you expected to happen, what actually happened". We have here only what you did and quite vaguely what happened (what were the error messages?), but not the rest. – mcepl Mar 08 '18 at 13:25
  • 1
    [@alchemist21](https://stackoverflow.com/users/9365023/alchemist21) it's probably `if (num == 6.5)` and `double num = Double.parseDouble(HbA1c.getText().toString())` – Stefan Golubović Mar 08 '18 at 13:30
  • the error messages were incomparable types: EditText and double then MyOnClickListener is not abstract and does not override abstract method onClick(View) in OnCLickListener – Louell Sala Mar 08 '18 at 13:39
  • Thanks. got the if then statement but my code still crashes after execution – Louell Sala Mar 08 '18 at 15:24

0 Answers0