[solved] DecimalType error in rule

The rule looks like this:

rule "ruleEMeterPower"
    when
        Item nPVGeneratorPac changed or
        Item nEMeterPPurchase changed
    then
        var Number nPowerPVGenerator = (nPVGeneratorPac.state as DecimalType)
        var Number nPowerEMeterPurchase = (nEMeterPPurchase.state as DecimalType)

        nEMeterPTotal.postUpdate(nPowerPVGenerator + nPowerEMeterPurchase)
end

When starting openHAB 2 the console gives the following error message:

[ERROR] [.script.engine.ScriptExecutionThread] - Rule ‘ruleEMeterPower’: org.eclipse.smarthome.core.library.types.DecimalType

However the rule seems to execute fine as the item nEMeterPTotal is updated correctly.

Still, I’d like to get rid of this error message.
So what could I do to fix this? Do I need to import something?
Thanks.

Taking that as a clue, I would think that perhaps one of your Items is null at startup.
You could wrap your code in an if() that checks that both item states are not-null before attempting.

Alright, that did the trick!
Thank you very much!

For reference, here’s the complete rule:

rule "ruleEMeterPower"
    when
        Item nPVGeneratorPac changed or
        Item nEMeterPPurchase changed
    then
        if ((nPVGeneratorPac.state != NULL) && (nEMeterPPurchase.state != NULL)) {
            var Number nPowerPVGenerator = (nPVGeneratorPac.state as DecimalType)
            var Number nPowerEMeterPurchase = (nEMeterPPurchase.state as DecimalType)

            nEMeterPTotal.postUpdate(nPowerPVGenerator + nPowerEMeterPurchase)
        }
end