help......i am a Beginners

by yoyo » Tue, 14 Apr 2009 00:58:56 GMT


Sponsored Links
 package com.androidyo.firstbmi;

import java.text.DecimalFormat;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class Bmi extends Activity {

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


        Button button=(Button)findViewById(R.id.submit);
        button.setOnClickListener(calcBMI);
    }
    private OnClickListener calcBMI = new OnClickListener()
    {
        public void onClick(View v)
        {
                DecimalFormat nf=new DecimalFormat("0.00");

                EditText fieldheight=(EditText)findViewById(R.id.height);
                EditText fieldweight = (EditText)findViewById(R.id.weight);
                double height = 
Double.parseDouble(fieldheight.getText().toString
());
                height=height/100;
                double weight = 
Double.parseDouble(fieldweight.getText().toString
());

                TextView result = (TextView)findViewById(R.id.result);
                TextView fieldsuggest = (TextView)findViewById(R.id.suggest);
                if(height<=0||weight<=0)
                        result.setText("input wrong");
                else
                {
                   double BMI = weight / (height * height);


             result.setText("Your BMI is "+nf.format(BMI));

             if(BMI>25){
                    fieldsuggest.setText(R.string.advice_heavy);
                   }else if(BMI<20){
                fieldsuggest.setText(R.string.advice_light);
                   }else{
                    fieldsuggest.setText(R.string.advice_average);
                   }
             }

        }

    };
}



MY question:



when runing the app .if i input nothing .it will force close

how can i fix it???
please give me a hang...i am a beginners.thanks

--~--~---------~--~----~------------~-------~--~----~



help......i am a Beginners

by Marco Nelissen » Tue, 14 Apr 2009 01:10:14 GMT


 You almost no information as to what goes wrong, but my guess is that
since you didn't input any values, the call to Double.parseDouble()
throws an exception.
BTW, since you say you're a beginner, you might want to give the
android-beginners mailing list a try.





--~--~---------~--~----~------------~-------~--~----~


Sponsored Links


help......i am a Beginners

by MrChaz » Tue, 14 Apr 2009 01:22:03 GMT


 You need to make sure that there is text in the TextEdits before
calling parseDouble because it will throw an exception otherwise.
Something like:

String heightText = fieldheight.getText().toString();
if( heightText  != null && !heightText.equals("")){
 // do stuff here
}

should work.



--~--~---------~--~----~------------~-------~--~----~



Other Threads

1. Will we need Android OS in the near future?

I'm noticing that smartphones are becoming more powerful and will soon
have the processing power of a laptop computer.  When this happens
wouldn't it be more suitable to have a fully-fledged OS on them?  If I
could have a phone with Ubuntu on it I could finally put all my Java,
C#, PHP apps on there and not have to worry about re-writing them or
waiting for someone to port them over.  If people still prefer
Android, thats great, but why can't it be part of the OS as a
framework?

--~--~---------~--~----~------------~-------~--~----~

2. DatePicker and calender in android ?

1. First of all i want to know that there is any control(View) in android
for DatePicker just like traditional Calender look, remember i m not
discussing android built in DatePicker control.

2. i used DialogDatePicker its working best, but when i use builtIn android
DatePicker Control (view) without dialog in my activity,
so i can't found setOnDateChangedListener listener in DatePicker. can any
body tell me how i handle the date change event without using DatePicker not
DialogDatePicker.

thanks

-- 
-----------------------------
Mohsin Yaseen
Android Developer, EASIP IMSciences
Consultant Software, Qurtuba Education System
http://www.linkedin.com/in/rmyasin
http://groups.yahoo.com/group/bPakistani/
+923349069919
+923129069919
rmya...@yahoo.com
myas...@gmail.com

--~--~---------~--~----~------------~-------~--~----~

3. Returning a value from TabActivity.

4. time of outgoing SMS

5. Icon and text on button

6. Question about drawing caches in the new SDK

7. Get the phone credentials to use Google Calendar API