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.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. */
    public void onCreate(Bundle savedInstanceState) {

        Button button=(Button)findViewById(;
    private OnClickListener calcBMI = new OnClickListener()
        public void onClick(View v)
                DecimalFormat nf=new DecimalFormat("0.00");

                EditText fieldheight=(EditText)findViewById(;
                EditText fieldweight = (EditText)findViewById(;
                double height = 
                double weight = 

                TextView result = (TextView)findViewById(;
                TextView fieldsuggest = (TextView)findViewById(;
                        result.setText("input wrong");
                   double BMI = weight / (height * height);

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

                   }else if(BMI<20){



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


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


Mohsin Yaseen
Android Developer, EASIP IMSciences
Consultant Software, Qurtuba Education System


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