0

有人可以看看下面的内容并尝试解释我所缺少的吗?我之前在应用程序中使用过以下方法,并且效果很好。我确定它是我错过的一些愚蠢的东西,并且很想找人来看看它......

我输入风量和压力,然后单击我的 RadioButton ForwardCBD。这应该会产生双重力量,然后应该将其输出到屏幕上,但会导致应用程序崩溃。

有任何想法吗?

EditText AirVolume, Pressure,FCBD,BCBD,BCDD;
TextView Power;
RadioGroup Fans;
RadioButton ForwardCBD, BackwardCBD, BackwardCDD;


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

    AirVolume=(EditText)findViewById(R.id.AirVolume);
    Pressure=(EditText)findViewById(R.id.Pressure);

    Power=(TextView)findViewById(R.id.Power);

    ForwardCBD=(RadioButton)findViewById(R.id.ForwardCBD);
    BackwardCBD=(RadioButton)findViewById(R.id.BackwardCBD);
    BackwardCDD=(RadioButton)findViewById(R.id.BackwardCDD);

    Fans=(RadioGroup)findViewById(R.id.Fans);
    Fans.setOnCheckedChangeListener(this);

}   

public void onCheckedChanged(RadioGroup Fans, int aplication) {

    if (aplication==R.id.ForwardCBD){

        double airVolume = Double.parseDouble(AirVolume.getText().toString());
        double pressure = Double.parseDouble(Pressure.getText().toString());
        double fCBD = Double.parseDouble(FCBD.getText().toString());        
        double power = (airVolume * pressure) / (fCBD /100);
        DecimalFormat df = new DecimalFormat();
        Power.setText(df.format(power)+("W"));

    }
    if (aplication==R.id.BackwardCBD){

        double airVolume = Double.parseDouble(AirVolume.getText().toString());
        double pressure = Double.parseDouble(Pressure.getText().toString());
        double bCBD = Double.parseDouble(BCBD.getText().toString());        
        double power = (airVolume * pressure) / (bCBD /100);
        DecimalFormat df = new DecimalFormat();
        Power.setText(df.format(power)+("W"));

    }
    if (aplication==R.id.BackwardCDD){
        double airVolume = Double.parseDouble(AirVolume.getText().toString());
        double pressure = Double.parseDouble(Pressure.getText().toString());
        double bCDD = Double.parseDouble(BCDD.getText().toString());        
        double power = (airVolume * pressure) / (bCDD /100);
        DecimalFormat df = new DecimalFormat();
        Power.setText(df.format(power)+("W"));
    }

}   
}

请参阅下面的 LogCat。

不太确定如何在这里以体面的格式呈现它,所以提前抱歉!

08-19 12:10:24.576: E/AndroidRuntime(11733): FATAL EXCEPTION: main
08-19 12:10:24.576: E/AndroidRuntime(11733): java.lang.NullPointerException
08-19 12:10:24.576: E/AndroidRuntime(11733):    at com.test.will.CarSystems.onCheckedChanged(CarSystems.java:46)
08-19 12:10:24.576: E/AndroidRuntime(11733):    at android.widget.RadioGroup.setCheckedId(RadioGroup.java:172)
08-19 12:10:24.576: E/AndroidRuntime(11733):    at android.widget.RadioGroup.access$600(RadioGroup.java:52)
08-19 12:10:24.576: E/AndroidRuntime(11733):    at android.widget.RadioGroup$CheckedStateTracker.onCheckedChanged(RadioGroup.java:342)
08-19 12:10:24.576: E/AndroidRuntime(11733):    at android.widget.CompoundButton.setChecked(CompoundButton.java:128)
08-19 12:10:24.576: E/AndroidRuntime(11733):    at android.widget.CompoundButton.toggle(CompoundButton.java:87)
08-19 12:10:24.576: E/AndroidRuntime(11733):    at android.widget.RadioButton.toggle(RadioButton.java:75)
08-19 12:10:24.576: E/AndroidRuntime(11733):    at android.widget.CompoundButton.performClick(CompoundButton.java:99)
08-19 12:10:24.576: E/AndroidRuntime(11733):    at android.view.View$PerformClick.run(View.java:14400)
08-19 12:10:24.576: E/AndroidRuntime(11733):    at android.os.Handler.handleCallback(Handler.java:605)
08-19 12:10:24.576: E/AndroidRuntime(11733):    at android.os.Handler.dispatchMessage(Handler.java:92)
08-19 12:10:24.576: E/AndroidRuntime(11733):    at android.os.Looper.loop(Looper.java:154)
08-19 12:10:24.576: E/AndroidRuntime(11733):    at android.app.ActivityThread.main(ActivityThread.java:4945)
08-19 12:10:24.576: E/AndroidRuntime(11733):    at java.lang.reflect.Method.invokeNative(Native Method)
08-19 12:10:24.576: E/AndroidRuntime(11733):    at java.lang.reflect.Method.invoke(Method.java:511)
08-19 12:10:24.576: E/AndroidRuntime(11733):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
08-19 12:10:24.576: E/AndroidRuntime(11733):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
08-19 12:10:24.576: E/AndroidRuntime(11733):    at dalvik.system.NativeStart.main(Native Method)
4

1 回答 1

1

您在哪里为 FCBD、BCBD、BCDD 分配了组件;这可能是空指针。

你的呼唤

double fCBD = Double.parseDouble(FCBD.getText().toString());

但是您在哪里定义/分配了 FCBD 即

FCBD=(EditText)findViewById(R.id.FCBD);

否则,在调试模式下单步执行,您会发现您的一个属性为空,您试图调用一个方法。

于 2012-08-19T11:17:26.430 回答