Radio Group崩溃的应用程序

时间:2012-08-15 09:51:35

标签: java android

我有以下困难。我认为代码是正确的,但是当我进行此活动时,它会导致应用程序崩溃吗?

任何人都可以帮助我并指出我缺少的东西吗?

import java.text.DecimalFormat;
import android.app.Activity;
import android.os.Bundle;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;


public  class CanopySizer extends Activity implements RadioGroup.OnCheckedChangeListener{

EditText CanopyLength, CanopyWidth;
TextView Volume;
RadioButton Light, Medium, Heavy;
RadioGroup Loadings;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.canopysizer);

    CanopyLength=(EditText)findViewById(R.id.CanopyL);
    CanopyWidth=(EditText)findViewById(R.id.CanopyW);
    Volume=(TextView)findViewById(R.id.Volume);
    Light=(RadioButton)findViewById(R.id.Light);
    Medium=(RadioButton)findViewById(R.id.Medium);
    Heavy=(RadioButton)findViewById(R.id.Heavy);
    Loadings=(RadioGroup)findViewById(R.id.Loading);
    Loadings.setOnCheckedChangeListener(this);

}


public void onCheckedChanged(RadioGroup Loadings, int aplication) {

    if (aplication==Light.getId()){
        double Canopylength = Double.parseDouble(CanopyLength.getText().toString());
        double Canopywidth = Double.parseDouble(CanopyWidth.getText().toString());
        double CanopyArea = Canopylength * Canopywidth;
        double ExtractionRate = CanopyArea * 0.25;
        DecimalFormat df = new DecimalFormat();
        Volume.setText(df.format(ExtractionRate));
    }
    if (aplication==Medium.getId()){
        double Canopylength = Double.parseDouble(CanopyLength.getText().toString());
        double Canopywidth = Double.parseDouble(CanopyWidth.getText().toString());
        double CanopyArea = Canopylength * Canopywidth;
        double ExtractionRate = CanopyArea * 0.35;
        DecimalFormat df = new DecimalFormat();
        Volume.setText(df.format(ExtractionRate));
            }       
    if (aplication==Heavy.getId()){
        double Canopylength = Double.parseDouble(CanopyLength.getText().toString());
        double Canopywidth = Double.parseDouble(CanopyWidth.getText().toString());
        double CanopyArea = Canopylength * Canopywidth;
        double ExtractionRate = CanopyArea * 0.50;
        DecimalFormat df = new DecimalFormat();
        Volume.setText(df.format(ExtractionRate));

    }
}

}

1 个答案:

答案 0 :(得分:0)

事实证明,用if (aplication==Light.getId()){替换行if (aplication==R.id.Light){已经成功了。该应用程序不再崩溃。

干杯。