Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6336005
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T18:57:57+00:00 2026-05-24T18:57:57+00:00

I met this error of javax.faces.el.EvaluationException: java.lang.NullPointerException Code of my controller method: public String

  • 0

I met this error of javax.faces.el.EvaluationException: java.lang.NullPointerException

Code of my controller method:

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 of my StaffFacadeLocal:

public interface StaffFacadeLocal {

void create(Staff staff);

void edit(Staff staff);

void remove(Staff staff);

Staff find(Object id);

List<Staff> findAll();

List<Staff> findRange(int[] range);

int count();

public List findByName(String string);

public int getVerifyCodeByName(String name);

}

Code of my StaffFacade:

public class StaffFacade /*extends AbstractFacade<Staff>*/ 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<Staff> findAll() {
    CriteriaQuery cq = em.getCriteriaBuilder().createQuery();

    cq.select(cq.from(Staff.class));
    return em.createQuery(cq).getResultList();
}

@Override
public List<Staff> 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<Staff> 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<Staff> 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;
 }
}


}

My Staff entity:

@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 && other.staffId != null) || (this.staffId != null && !this.staffId.equals(other.staffId))) {
        return false;
    }
    return true;
}

@Override
public String toString() {
    return "entity.Staff[ staffId=" + staffId + " ]";
}

}

I am not sure which part of my controller returned a null value. Anyone can point out for me? Thanks alot!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T18:57:58+00:00Added an answer on May 24, 2026 at 6:57 pm

    I suspect it’s this code:

     Query q = em.createNamedQuery("Staff.getVerifyCodeByName");
     ...
     int id = (int)q.getSingleResult();
    

    Assuming the named query in fact returns a Staff entity, the cast to int would fail.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have met the error when I am implementing a method in Netbeans. java.lang.IllegalArgumentException:
This code gives you an error in the error list of VS 2010: let
I use both version on windows and ubuntu. I met this error on both.
All the Perl dependencies for it are met but I'm getting this error: Can't
guys I know this question is very basic but I've met in few publications
I met an interesting issue about C#. I have code like below. List<Func<int>> actions
I met a problem when trying @Singleton of Guice: import com.google.inject.Singleton; @Singleton public class
I'm getting this error when trying to save a file in Xcode 4: The
I am using Matlab and am using its solve function. I run this code
I've met an unknown error while inserting data into the database. The LogCat had

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.