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


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 extends ListActivity {
    ListAdapter list;
    onCreate {
       new BackgroundThread(this);
    public synchronized addParsedData(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


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 that describe my
board configuration.

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

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

the_product_1 not found.
I also try with the device folder, like:

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

Note that first configuration can build and generate image with make

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



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