2012-08-15 86 views
0

Im与下面有困难。我相信代码是正确的,但是当我开始这个活动时,它会导致应用程序崩溃?无线电组碰撞应用程序

任何人都可以帮助我,并指出我错过了什么?

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)); 

    } 
} 

} 
+2

put logcat和xml文件 – 2012-08-15 09:53:02

+1

您确定没有收到NumberFormatException? – 2012-08-15 10:15:46

回答

0

那么原来只是更换线if (aplication==Light.getId()){if (aplication==R.id.Light){做的伎俩。该应用程序不再崩溃。

干杯。