本帖最后由 tongcpp 于 2011-08-05 00:19:06 编辑

解决方案 »

  1.   

    模拟器中点击按钮后出现【Force close】:SORRY!The Application 体质指数BMI测试工程(process com.demo.android.bmi)has stopped unexpectedly.Please rry again!
    点击【Force close】后就关闭程序退出了。
    thanku!
      

  2.   

    http://www.eoeandroid.com/thread-9290-1-1.html
      

  3.   

    只要把OpenOptionsDialog();改成openOptionsdialog();就可以解决了
      

  4.   

    package com.demo.android.bmi;
    import java.text.DecimalFormat;import android.app.Activity;
    import android.app.AlertDialog;
    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);        findViews();
            setListeners();
        }//onCreate
        
        private Button button_calc;
        private EditText field_height;
        private EditText field_weight;
        private TextView view_result;
        private TextView view_suggest;
        private void findViews() {
         button_calc = (Button) findViewById(R.id.submit);
         field_height = (EditText) findViewById(R.id.height);
         field_weight = (EditText) findViewById(R.id.weight);
         view_result = (TextView) findViewById(R.id.result);
         view_suggest = (TextView) findViewById(R.id.suggest);
        }//findViews
        
        private void setListeners() {
         button_calc.setOnClickListener(calcBMI);
        }//setListeners
           
        private Button.OnClickListener calcBMI = new Button.OnClickListener() {  
         public void onClick(View v) {
         DecimalFormat nf = new DecimalFormat("0.00");     double height = Double.parseDouble(field_height.getText().toString()) / 100;
         double weight = Double.parseDouble(field_weight.getText().toString());
         double BMI = weight / (height * height);
      
         view_result.setText(getText(R.string.bmi_result) + nf.format(BMI));
        
         if(BMI > 25) {
         view_suggest.setText(R.string.advice_heavy);
         } else if (BMI < 20) {
         view_suggest.setText(R.string.advice_light);
         } else {
         view_suggest.setText(R.string.advice_average);
         }
         openOptionsDialog();
         }//onClick
        };
        private void openOptionsDialog() {
         AlertDialog.Builder builder = new AlertDialog.Builder(Bmi.this);
         builder.setTitle("关于 Android BMI");
         builder.setMessage("Android BMI Calc");
         builder.show();
        }
    }
      

  5.   

    LZ openOptionsDialog() 函数的定义位置有误~应按楼上的位置定义
      

  6.   

    问题已经解决了哈,看这个地址http://hi.baidu.com/ruiqing_2008/blog/item/5190b6facd9bd69e58ee904a.html
    要在AndroidManifest.xml中的application 里添加一个label就行了