安卓程序出错了,求高手指点啊!
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.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class BmiActivity<bmi, BMI> extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_bmi);
findViews();
setListeners();
}
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);
}
private void setListeners()
{
button_calc.setOnClickListener(calcBMI);
}
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();
}
public void openOptionsDialog()
{AlertDialog.Builder builder=new AlertDialog.Builder(bmi.this);
builder.setTitle("关于Android BMI");
builder.setMessage("Android BMI Calc");
builder.show();
}
};
}
标红色的地方错误了。
系统显示:bmi_result cannot be resolved or is not a field
The constructor AlertDialog.Builder(Object) is undefined
请问是怎么回事啊??菜鸟纠结了一整天了! --------------------编程问答-------------------- 除 --------------------编程问答-------------------- 谢谢楼主分享。
补充:Java , Eclipse