Pregunta

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?

¿Fue útil?

Solución

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;
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top