-3

How to know the Employees.class is null or not using Java Relection?

Example Class: Employees.class

Problem:

  • employees.getName();
  • value getName is Mikel
  • employees is null
  • if employess != null is TRUE.
  • this class already 'new Employees()'

Employees.Class

public class Employees{

private Long id;<br>
private String kodStuff;<br>
private String Name;<br>

//Getter and Setter<br>
}

Example Process Method:

public void check(){
    Employees employees = new Empoyees;
    employees.setName("Mikel");
    employees.setKodStuff("KL370");
    //employees not save yet and process redirect check value of Name wuth return boolean
    Boolean empty = checkName(employees);

}

public boolean checkName(Employees employees){
    boolean notNull = false;
    if(employees !=null && StringUtils.isNotBlank(employees.getName())){ // this is line 11
        notNull = true;
    }
    return notNull;
}

Throws exception at line no '11':

java.lang.NullPointerException

How can i check null exception during process on line no.11?

Ryan
  • 21
  • 1
  • 6

1 Answers1

0

Try checking if employees.getName() is null or not by doing:
employees.getName() != null

Brokemia
  • 54
  • 12