Welcome to the Android Central Forums Create Your Account or Ask a Question Answers in 5 minutes - no registration required!
Results 1 to 1 of 1
  1. Thread Author  Thread Author    #1  

    Default Simple BMI calculator in Android. parse Integer not working

    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);
    }


    }

Similar Threads

  1. Stock Android mail client not working with Yahoo
    By mannyvigi1985 in forum Verizon HTC Rezound
    Replies: 4
    Last Post: 07-05-2012, 05:22 PM
  2. Yahoo News Feed In Stock News App Not Working?
    By flywithlloyd in forum HTC EVO 4G
    Replies: 0
    Last Post: 03-01-2012, 08:48 PM
  3. Replies: 9
    Last Post: 12-24-2011, 07:50 PM
  4. android media player not working
    By bjs188 in forum Sprint Epic 4G
    Replies: 0
    Last Post: 05-09-2011, 10:08 AM
  5. (help) in u.k. Voice not working
    By anneoneamouse in forum AT&T Captivate
    Replies: 0
    Last Post: 08-26-2010, 06:36 AM

Posting Permissions