How to handle null exeption

94 views
Skip to first unread message

Artyom

unread,
May 2, 2015, 4:59:03 PM5/2/15
to ope...@googlegroups.com
Hi, need help with persistence:

var pwr = (PwrCounter.historicState(now.toDateMidnight, "rrd4j").state as DecimalType


I got error:

2015-05-02 23:55:03.243 [ERROR] [.o.m.r.i.engine.ExecuteRuleJob] - Error during the execution of rule Counters plus
java
.lang.NullPointerException: cannot invoke method public abstract org.openhab.core.types.State org.openhab.core.persistence.HistoricItem.getState() on null

How to handle null exeption?

Алексей Власов

unread,
May 3, 2015, 5:16:22 AM5/3/15
to ope...@googlegroups.com
if (PwrCounter.historicState(now.toDateMidnight, "rrd4j").state != null) { 
var pwr = (PwrCounter.historicState(now.toDateMidnight, "rrd4j").state as DecimalType
} else {...}

--
You received this message because you are subscribed to the Google Groups "openhab" group.
To unsubscribe from this group and stop receiving emails from it, send an email to openhab+u...@googlegroups.com.
To post to this group, send email to ope...@googlegroups.com.
Visit this group at http://groups.google.com/group/openhab.
To view this discussion on the web visit https://groups.google.com/d/msgid/openhab/efaa23a7-a5d4-43e2-b0ce-963351932d7a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
С уважением,
Алексей А. Власов

Artyom

unread,
May 3, 2015, 4:28:39 PM5/3/15
to ope...@googlegroups.com
doesnt work
rule "Counters plus"
when
   
Time cron "0 * * * * ?"
then

    if (PwrCounter.historicState(now.toDateMidnight, "rrd4j").state != null) {
       
var pwr = (PwrCounter.historicState(now.toDateMidnight, "rrd4j").state as DecimalType

    logInfo
("PwrCounter.historicState="+ pwr.toString)
   
}
end




2015-05-03 23:27:03.737 [ERROR] [.o.m.r.i.engine.ExecuteRuleJob] - Error during the execution of rule Counters plus
java
.lang.NullPointerException: null
    at org
.openhab.model.script.lib.NumberExtensions.operator_notEquals(NumberExtensions.java:89) ~[na:na]
    at sun
.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.7.0_79]
    at sun
.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) ~[na:1.7.0_79]
    at sun
.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.7.0_79]
......



воскресенье, 3 мая 2015 г., 12:16:22 UTC+3 пользователь Алексей Власов написал:
Reply all
Reply to author
Forward
0 new messages