Simple BMI calculator in Android. parse Integer not working

Isuru Uyanage

New member
Feb 27, 2013
1
0
0
Visit site
Hello, Im really new to Android. I'm developing a BMI Calculator. I did the coding, but I'm receiving an exception as I can't parse integer values.
This is my interface and my coding. Please help me with this.
thanx loads
Best Regards
Isuru Uyanage

public class Main extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

try{
EditText et1=(EditText) findViewById(R.id.editText1);
String heightS=et1.getText().toString();
int height=Integer.parseInt(heightS);

EditText et2=(EditText) findViewById(R.id.editText2);
String weightS=et2.getText().toString();
int weight=Integer.parseInt(weightS);

final int bmi=weight/(height*height);

Button cal=(Button) findViewById(R.id.button1);
cal.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v) {
EditText et3=(EditText) findViewById(R.id.editText3);
et3.setText(Integer.toString(bmi));

}
});
}
catch(NumberFormatException nfe){
System.out.println("Could not parse " + nfe);
}


}