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. performance when passing background data to ui thread

Hi

I've got an app that spawns of a seperate thread. Parses JSON data into a 
structure. And passes it back to the main thread through a handler. Each 
part of data is sent through the handler individually. That worked fairly 
well with my previous XML parser, as XML parses data while it downloads. But 
JSON doesn't (atleast I haven't found a way to get that working). In either 
way the JSON data is much smaller and much faster to parse.

I've recently added a feature that requires me to load several sources of 
json in parallel, parse in the background, and pass all the data back again 
using a Handler. This is a bit slower than I was hoping.

Would it be faster (and possible) for me to do this:
BackgroundThread extends Thread {
    onCreate (Parent) {
        this.parent = parent;
    }
    onData {
        parent.addParsedData(x);
    }
}

Parent extends ListActivity {
    ListAdapter list;
    onCreate {
       setListAdapter(list);
       new BackgroundThread(this);
    }
    public synchronized addParsedData(data) {
        list.add(data)
    }
}

I'm thinking this won't be thread safe, as ListAdapter is in the parent 
thread. Am I right?
Should I instead inside the listadapter (which puts data in an array) have 
synchronized access to it's items?

-- 

2. Froyo porting, vendor & device folder, and build for a device with tapas

Hello,

i try to build Froyo for a given dev board, but i don't know how to
configure the source tree, especially where should put the board
specific code and the board configuration mkf ile, either in vendor or
device ?

I first put my board specific code and config file in the vendor
folder as:

vendor\cpyname\the_product_1\, with BoardConfig.mk that describe my
board configuration.

I then have vendor\cpyname\product\ with the_product_1.mk to start the
source tree build.

can't build with tapas, when giving product name (the_product_1), i
get an error

build/core/product_configuration.mk
the_product_1 not found.
I also try with the device folder, like:

device\the_product_1\ with BoardConfig.mk,
and device\the_product_1\product\ with the_product_1.mk
tapas give the same result.

Note that first configuration can build and generate image with make
PRODUCT-the_product_1-eng

I also personally find the build process quite obscure and missing
documentation. Please help :)

Lionel

-- 

3. System Bar location and height in Honeycomb?

4. lrzsz on android

5. USB: android gadget: issue in interface_number while using USB CV.

6. NDK Toolchain and "Unknown symbol _GLOBAL_OFFSET_TABLE_" in kernel module

7. PreferenceActivity how to display ListPreference value