سؤال

I defined a Double instance variable like this:

public class CurrencyActivity extends Activity {

    private Button convertBtn;
    private Double SEKrate;

....
public void convertCurrency() {
....
Double inputNum = Double.parseDouble(editTextStr);
Double result = inputNum*SEKrate;
....
}
....
}

When running, it says NullPointer exception at the line

Double result = inputNum*SEKrate;

It seems like SEKrate is initialized to null, but autoboxing is not performed here. any thought on this?

هل كانت مفيدة؟

المحلول

If you do not initialize a Double it is null and null can not be unboxed to a double.

So initalize your variable.

  private Double SEKrate=0;
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top