title: how to resolve a java.lang.NullPointerException?
body: <p>my application use jsf2 primefaces5 and spring ,and I try to implement a lazy datatabe,
  I am getting the following error when I select a row in the lazy datatable :</p>
  
  <pre><code>Avertissement: java.lang.NullPointerException
  javax.el.ELException: java.lang.NullPointerException
      at com.sun.el.parser.AstValue.invoke(AstValue.java:238)
      at com.sun.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:297)
      at org.primefaces.behavior.ajax.AjaxBehaviorListenerImpl.processCustomListener(AjaxBehaviorListenerImpl.java:87)
      at org.primefaces.behavior.ajax.AjaxBehaviorListenerImpl.processArgListener(AjaxBehaviorListenerImpl.java:72)
      at org.primefaces.behavior.ajax.AjaxBehaviorListenerImpl.processAjaxBehavior(AjaxBehaviorListenerImpl.java:56)
      at org.primefaces.event.SelectEvent.processListener(SelectEvent.java:40)
      at javax.faces.component.behavior.BehaviorBase.broadcast(BehaviorBase.java:98)
      at javax.faces.component.UIComponentBase.broadcast(UIComponentBase.java:764)
      at javax.faces.component.UIData.broadcast(UIData.java:890)
      at javax.faces.component.UIData.broadcast(UIData.java:912)
      at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:781)
      at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1246)
      at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:77)
      at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:97)
      at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:114)
      at javax.faces.webapp.FacesServlet.service(FacesServlet.java:308)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
      at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
      at org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter.doFilterInternal(OpenEntityManagerInViewFilter.java:113)
      at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
      at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
      at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
      at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1040)
      at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:607)
      at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:315)
      at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
      at java.lang.Thread.run(Unknown Source)
  Caused by: java.lang.NullPointerException
      at com.gestion.projet.web.jsf.Lazy.onRowSelect(Lazy.java:68)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
      at java.lang.reflect.Method.invoke(Unknown Source)
      at com.sun.el.parser.AstValue.invoke(AstValue.java:234)
      ... 38 more
  
  javax.faces.FacesException: java.lang.NullPointerException
      at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:85)
      at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:97)
      at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:114)
      at javax.faces.webapp.FacesServlet.service(FacesServlet.java:308)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
      at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
      at org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter.doFilterInternal(OpenEntityManagerInViewFilter.java:113)
      at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
      at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
      at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
      at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1040)
      at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:607)
      at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:315)
      at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
      at java.lang.Thread.run(Unknown Source)
  Caused by: javax.el.ELException: java.lang.NullPointerException
      at com.sun.el.parser.AstValue.invoke(AstValue.java:238)
      at com.sun.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:297)
      at org.primefaces.behavior.ajax.AjaxBehaviorListenerImpl.processCustomListener(AjaxBehaviorListenerImpl.java:87)
      at org.primefaces.behavior.ajax.AjaxBehaviorListenerImpl.processArgListener(AjaxBehaviorListenerImpl.java:72)
      at org.primefaces.behavior.ajax.AjaxBehaviorListenerImpl.processAjaxBehavior(AjaxBehaviorListenerImpl.java:56)
      at org.primefaces.event.SelectEvent.processListener(SelectEvent.java:40)
      at javax.faces.component.behavior.BehaviorBase.broadcast(BehaviorBase.java:98)
      at javax.faces.component.UIComponentBase.broadcast(UIComponentBase.java:764)
      at javax.faces.component.UIData.broadcast(UIData.java:890)
      at javax.faces.component.UIData.broadcast(UIData.java:912)
      at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:781)
      at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1246)
      at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:77)
      ... 26 more
  Caused by: java.lang.NullPointerException
      at com.gestion.projet.web.jsf.Lazy.onRowSelect(Lazy.java:68)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
      at java.lang.reflect.Method.invoke(Unknown Source)
      at com.sun.el.parser.AstValue.invoke(AstValue.java:234)
      ... 38 more
  </code></pre>
  
  <p>and then the code associated with the following bean method:</p>
  
  <pre><code>@ManagedBean(name="lazyBean")
      @ViewScoped
      public class Lazy extends LazyDataModel&lt;Projet&gt;  {
   public void onRowSelect(SelectEvent event) {
              FacesMessage msg = new FacesMessage("Projet Selected", ((Projet) event.getObject()).getIdprojet().toString());
              FacesContext.getCurrentInstance().addMessage(null, msg);
          }
  </code></pre>
  
  <p>and this the xhtml page:</p>
  
  <pre><code>&lt;h:form id="form"&gt;
              &lt;p:dataTable var="current" value="#{ProjetComponent.lazyModel}"  
                  paginator="true" rows="10" 
                  paginatorTemplate="{RowsPerPageDropdown} {FirstPageLink} {PreviousPageLink} {CurrentPageReport} {NextPageLink} {LastPageLink}"
                  rowsPerPageTemplate="5,10,15" selectionMode="single"
                  selection="#{ProjetComponent.projet}" id="projetTable" lazy="true"&gt;
                  &lt;p:ajax event="rowSelect" listener="#{ProjetComponent.onRowSelect}"
                      update=":form:projetDetail" oncomplete="PF('projetDialog').show()" /&gt;
                  &lt;p:column headerText="Id" sortBy="#{current.idprojet}" filterBy="#{current.idprojet}"&gt;
                      &lt;h:outputText value="#{current.idprojet}" /&gt;
                  &lt;/p:column&gt;
                  &lt;p:column headerText="Nom" sortBy="#{current.nomprojet}"
                      filterBy="#{current.nomprojet}"&gt;
                      &lt;h:outputText value="#{current.nomprojet}" /&gt;
                  &lt;/p:column&gt;
  
              &lt;/p:dataTable&gt;
  
              &lt;p:dialog header="Projet Detail" widgetVar="projetDialog" modal="true"
                  showEffect="fade" hideEffect="fade" resizable="false"&gt;
                  &lt;p:outputPanel id="projetDetail" style="text-align:center;"&gt;
                      &lt;p:panelGrid columns="2"
                          rendered="#{not empty ProjetComponent.projet}"
                          columnClasses="label,value"&gt;
                          &lt;f:facet name="header"&gt;
  
                          &lt;/f:facet&gt;
  
                          &lt;h:outputText value="Id:" /&gt;
                          &lt;h:outputText value="#{ProjetComponent.projet.idprojet}" /&gt;
  
                          &lt;h:outputText value="Nom:" /&gt;
                          &lt;h:outputText value="#{ProjetComponent.projet.nomprojet}" /&gt;
  
                      &lt;/p:panelGrid&gt;
                  &lt;/p:outputPanel&gt;
              &lt;/p:dialog&gt;
          &lt;/h:form&gt;
  </code></pre>