title: javax.faces.el.EvaluationException: java.lang.NullPointerException
body: <p>I met this error of javax.faces.el.EvaluationException: java.lang.NullPointerException</p>
  
  <p>Code of my controller method:</p>
  
  <pre><code>public String verify(){
  String result = "failed";
  int authcode = staffBean.getVerifyCodeByName(getLoginUserName()); //get verifycode from database by name
  Staff temp = staffBean.find(authcode);
  
  if ( code==authcode){
      result ="success";
      staff.setVerifystatus("Verified");
      staffBean.edit(temp);
  }
  return result;
  </code></pre>
  
  <p>}</p>
  
  <p>Code of my StaffFacadeLocal:</p>
  
  <pre><code>public interface StaffFacadeLocal {
  
  void create(Staff staff);
  
  void edit(Staff staff);
  
  void remove(Staff staff);
  
  Staff find(Object id);
  
  List&lt;Staff&gt; findAll();
  
  List&lt;Staff&gt; findRange(int[] range);
  
  int count();
  
  public List findByName(String string);
  
  public int getVerifyCodeByName(String name);
  
  }
  </code></pre>
  
  <p>Code of my StaffFacade:</p>
  
  <pre><code>public class StaffFacade /*extends AbstractFacade&lt;Staff&gt;*/ implements StaffFacadeLocal{
  @PersistenceContext(unitName = "MajorProject-ejbPU")
  private EntityManager em;
  
  protected EntityManager getEntityManager() {
      return em;
  }
  @Override
  public void create(Staff staff) {
      em.persist(staff);
  }
  
  @Override
  public void edit(Staff staff) {
      em.merge(staff);
  }
  
  @Override
  public void remove(Staff staff) {
      em.remove(em.merge(staff));
  }
  
  @Override
  public Staff find(Object code) {
      return em.find(Staff.class, code);
  }
  
  @Override
  public List&lt;Staff&gt; findAll() {
      CriteriaQuery cq = em.getCriteriaBuilder().createQuery();
  
      cq.select(cq.from(Staff.class));
      return em.createQuery(cq).getResultList();
  }
  
  @Override
  public List&lt;Staff&gt; findRange(int[] range) {
      CriteriaQuery cq = em.getCriteriaBuilder().createQuery();
      cq.select(cq.from(Staff.class));
      Query q = em.createQuery(cq);
      q.setMaxResults(range[1] - range[0]);
      q.setFirstResult(range[0]);
      return q.getResultList();
  }
  
  @Override
  public int count() {
      CriteriaQuery cq = em.getCriteriaBuilder().createQuery();
      Root&lt;Staff&gt; rt = cq.from(Staff.class);
      cq.select(em.getCriteriaBuilder().count(rt));
      Query q = em.createQuery(cq);
      return ((Long) q.getSingleResult()).intValue();
  }
  /*public StaffFacade() {
      super(Staff.class);
  }
  */
  @Override
       public List&lt;Staff&gt; findByName(String search1) {
      Query q = em.createNamedQuery("Staff.findByName");
      q.setParameter("name", search1);
      return q.getResultList();
  }
  
  
  
  public int getVerifyCodeByName(String name) {
   Query q = em.createNamedQuery("Staff.getVerifyCodeByName");
   q.setParameter("name", name);
   try{
   int id = (int)q.getSingleResult();
   return id;
   }
   catch(NoResultException e){
       return -1;
   }
  }
  
  
  }
  </code></pre>
  
  <p>My Staff entity:</p>
  
  <pre><code>@Entity
  @Table(name = "staff")
  @XmlRootElement
  @NamedQueries({
  @NamedQuery(name = "Staff.findAll", query = "SELECT s FROM Staff s"),
  @NamedQuery(name = "Staff.findByStaffId", query = "SELECT s FROM Staff s WHERE s.staffId = :staffId"),
  @NamedQuery(name = "Staff.findByName", query = "SELECT s FROM Staff s WHERE s.name = :name"),
  @NamedQuery(name = "Staff.findByPassword", query = "SELECT s FROM Staff s WHERE s.password = :password"),
  @NamedQuery(name = "Staff.findByRoles", query = "SELECT s FROM Staff s WHERE s.roles = :roles"),
  @NamedQuery(name = "Staff.findByEmail", query = "SELECT s FROM Staff s WHERE s.email = :email"),
  @NamedQuery(name = "Staff.getVerifyCodeByName", query = "SELECT s.verifycode FROM Staff s WHERE s.name =:name"),
  @NamedQuery(name = "Staff.findByVerifystatus", query = "SELECT s FROM Staff s WHERE s.verifystatus = :verifystatus"),
  @NamedQuery(name = "Staff.findByVerifycode", query = "SELECT s FROM Staff s WHERE s.verifycode = :verifycode")})
  public class Staff implements Serializable {
  private static final long serialVersionUID = 1L;
  @Id
  @GeneratedValue(strategy = GenerationType.IDENTITY)
  @Basic(optional = false)
  //@NotNull
  @Column(name = "STAFF_ID")
  private Integer staffId;
  @Size(max = 30)
  @Column(name = "NAME")
  private String name;
  @Size(max = 64)
  @Column(name = "PASSWORD")
  private String password;
  @Size(max = 20)
  @Column(name = "ROLES")
  private String roles;
  @Size(max = 60)
  @Column(name = "EMAIL")
  private String email;
  @Size(max = 20)
  @Column(name = "VERIFYSTATUS")
  private String verifystatus;
  @Basic(optional = false)
  @NotNull
  @Column(name = "VERIFYCODE")
  private int verifycode;
  
  public Staff() {
  }
  
  public Staff(Integer staffId) {
      this.staffId = staffId;
  }
  
  public Staff(Integer staffId, int verifycode) {
      this.staffId = staffId;
      this.verifycode = verifycode;
  }
  
  public Integer getStaffId() {
      return staffId;
  }
  
  public void setStaffId(Integer staffId) {
      this.staffId = staffId;
  }
  
  public String getName() {
      return name;
  }
  
  public void setName(String name) {
      this.name = name;
  }
  
  public String getPassword() {
      return password;
  }
  
  public void setPassword(String password) {
      this.password = password;
  }
  
  public String getRoles() {
      return roles;
  }
  
  public void setRoles(String roles) {
      this.roles = roles;
  }
  
  public String getEmail() {
      return email;
  }
  
  public void setEmail(String email) {
      this.email = email;
  }
  
  public String getVerifystatus() {
      return verifystatus;
  }
  
  public void setVerifystatus(String verifystatus) {
      this.verifystatus = verifystatus;
  }
  
  public int getVerifycode() {
      return verifycode;
  }
  
  public void setVerifycode(int verifycode) {
      this.verifycode = verifycode;
  }
  
  @Override
  public int hashCode() {
      int hash = 0;
      hash += (staffId != null ? staffId.hashCode() : 0);
      return hash;
  }
  
  @Override
  public boolean equals(Object object) {
      // TODO: Warning - this method won't work in the case the id fields are not set
      if (!(object instanceof Staff)) {
          return false;
      }
      Staff other = (Staff) object;
      if ((this.staffId == null &amp;&amp; other.staffId != null) || (this.staffId != null &amp;&amp; !this.staffId.equals(other.staffId))) {
          return false;
      }
      return true;
  }
  
  @Override
  public String toString() {
      return "entity.Staff[ staffId=" + staffId + " ]";
  }
  </code></pre>
  
  <p>}</p>
  
  <p>I am not sure which part of my controller returned a null value. Anyone can point out for me? Thanks alot!</p>