解决方案 »

  1.   

    空指针了啊
    oncreate里空指针了
      

  2.   

    package zfy.Ex11_UI_A;
    import android.app.Activity;
    import android.os.Bundle;
    import java.text.DecimalFormat;
    import java.text.NumberFormat;//import zyf.Ex11_UI_A.R;
    import android.content.Intent;
    import android.view.View;
    import android.widget.Button;
    import android.widget.TextView;
    public class BMIActivity extends Activity {
    private Intent intent;
    private Bundle bundle;
    @Overroid
    public void onCreate(Bundle saveInstanceState){
    super.onCreate(saveInstanceState);
    setContentView(R.layout.mylayout);
    intent=this.getIntent();
    bundle=intent.getExtras();
    String sex=bundle.getString("sex");
    double height=bundle.getDouble("height");
    String sexText="";
    if (sex.equals("M")){
    sexText="男性";
    }else
    {
    sexText="女性";
    }
    String weight=this.getWeight(sex,height);
    TextView tv1=(TextView) findViewById(R.id.Text_sex);
    tv1.setText(""+sexText+"/n你的身高是"+height+"厘米\n你的标准体重是"+weight+"公斤");
    Button b1=(Button)findViewById(R.id.button_back);
    b1.setOnClickListener(new Button.OnClickListener(){
    @Overroid
    public void onClick(View V){
    BMIActivity.this.setResult(RESULT_OK,intent);
    BMIActivity.this.finish();
    }
    });

    }
    private String format(double num){
    NumberFormat formatter = new DecimalFormat("0.00");
    String s = formatter.format(num);
    return s;

    }
    private String getWeight(String sex,Double height){
    String weight="";
    if (sex.equals("M")){
    weight=format((height - 80)*0.7);
    }else{
    weight = format((height - 70)*0.6);
    }
    return weight;
    }
    }