-2

I have class where

    @Enumerated(EnumType.STRING)
private StateOfDispatchToWD stateOfDispatchToWD = StateOfDispatchToWD.NONE;

And getter and setter:

public StateOfDispatchToWD getStateOfDispatchToWD() {
    return stateOfDispatchToWD;
}

public void setStateOfDispatchToWD(StateOfDispatchToWD stateOfDispatchToWD) {
    this.stateOfDispatchToWD = stateOfDispatchToWD;
}

and method:

public boolean isSuccessfullySentToWD() {
    return zoj.getStateOfDispatchToWD() == StateOfDispatchToWD.SUCCESSFULLY_DISPATCH;
}

and call it from JSF:

            <p:outputLabel value="OK"
                           rendered="#{Z.isSuccessfullySentToWD()}"/>

and sometimes I get:

[javax.enterprise.resource.webcontainer.jsf.lifecycle]
javax.el.ELException: //content/resources/zo.xhtml @240,92 rendered="#{Z.isSuccessfullySentToWD()}":
java.lang.NullPointerException:
javax.faces.FacesException:
javax.el.ELException: //content/resources/zo.xhtml @240,92 rendered="#{Z.isSuccessfullySentToWD()}":
java.lang.NullPointerException

but why? I'm afraid I don't understand. Thanks a lot.

user207421
  • 305,947
  • 44
  • 307
  • 483
Martin Hofman
  • 53
  • 1
  • 6
  • 2
    Because `Z` was null? – user207421 Jun 17 '22 at 07:44
  • Exception is on line " return zoj.getStateOfDispatchToWD() == StateOfDispatchToWD.SUCCESSFULLY_DISPATCH; " – Martin Hofman Jun 17 '22 at 07:49
  • No it isn't, Read the stack trace. It is in the EL, in the expression `#{Z.isSuccessfullySentToWD()}`. There is nothing to suggest you got any further. – user207421 Jun 17 '22 at 08:03
  • 1
    Duplicate of [What is a NullPointerException, and how do I fix it?](https://stackoverflow.com/questions/218384/what-is-a-nullpointerexception-and-how-do-i-fix-it) – user207421 Jun 17 '22 at 08:04
  • Can't tell if this is a duplicate without more information. Please provide a runnable example - specifically show exactly how `zoj` is initialized. – Adam Waldenberg Jun 17 '22 at 21:25

1 Answers1

0

Probably the scope of Z is wrong, try to put it in session or application scope