菜鸟求助:OpenOptionsDialog函数调用新建AlertDialog模拟器报错 本帖最后由 tongcpp 于 2011-08-05 00:19:06 编辑 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 模拟器中点击按钮后出现【Force close】:SORRY!The Application 体质指数BMI测试工程(process com.demo.android.bmi)has stopped unexpectedly.Please rry again!点击【Force close】后就关闭程序退出了。thanku! http://www.eoeandroid.com/thread-9290-1-1.html 只要把OpenOptionsDialog();改成openOptionsdialog();就可以解决了 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(); }} LZ openOptionsDialog() 函数的定义位置有误~应按楼上的位置定义 问题已经解决了哈,看这个地址http://hi.baidu.com/ruiqing_2008/blog/item/5190b6facd9bd69e58ee904a.html要在AndroidManifest.xml中的application 里添加一个label就行了 android 调用JAX-WS构造的webservice问题 关于android中UI线程与渲染线程的问题 android实现天气预报问题 新手求助 笔记本被盗 摄像头拍摄的画面派出所看不了 各位大大们推荐点入门android开发的书籍吧 安卓/linux中怎样调用原有的JNI so库函数 客户端与伺服器资料同步问题 如何关闭Android Studio对于错误拼写的英文单词的提示 android小说阅读器如何读取assets目录下的txt?悬赏50rmb android app 如何变现? android用canvas画图时坐标的问题 在eclipse中怎么总是启动前一个运行过的项目
点击【Force close】后就关闭程序退出了。
thanku!
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();
}
}
要在AndroidManifest.xml中的application 里添加一个label就行了