Nullpointerexception at return of method

Asked

Viewed 66 times

1

I am making a method to search the user logged in to the database. I’m having a NullPointerException in the return of this method

@RequestMapping(value = "/usuarioLogado", consumes = MediaType.APPLICATION_JSON_UTF8_VALUE, method = RequestMethod.POST)
public EntidadesAdministradores usuarioLogado(@RequestBody Usuarios usuarios) throws ServletException {

    Usuarios usuAutenticado = uService.buscarPorLogin(usuarios.getLogin());     
    usuarios = usuAutenticado;
    Long idUsuLogado = usuarios.getIdUsuario();

    EntidadesAdministradores administrador = new EntidadesAdministradores(); 
    if(usuarios.getFlagAdministrador()==1) 
        administrador = eaService.buscarUsuarioLogado(idUsuLogado);
        return  administrador;
}

my method buscaUsuarioLogado

public EntidadesAdministradores buscarUsuarioLogado(Long usuarioLogado ){       
    return eaRepository.buscarIdUsuarioLogado(usuarioLogado);
}

my method of Repository

@Query(value="Select e from EntidadesAdministradores e where e.usuarios  = :parametroId")
public EntidadesAdministradores buscarIdUsuarioLogado(@Param("parametroId") Long usuarioLogado);

Error log

java.lang.NullPointerException: null
at controller.LoginController.usuarioLogado(LoginController.java:93) ~[classes/:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_144]
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[na:1.8.0_144]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[na:1.8.0_144]
at java.lang.reflect.Method.invoke(Unknown Source) ~[na:1.8.0_144]
at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:205) ~[spring-web-4.3.9.RELEASE.jar:4.3.9.RELEASE]
  • The log with stack trace would help understand your problem...

  • @Tommelo edited the question

  • It’s likely that a simple debug in your method will help you understand the reason for Nullpointerexception. Anyone who sees the question and stack trace does not know what is on line 93 of your Logincontroller.java code.

  • line 93 is precisely when the administrator receives the method eaService.buscarUsuarioLogado(idUsuLogado)

  • Debug the method, put a breakpoint on that snippet and see everything that happens. See if the eaService attribute is being instantiated.

1 answer

0

I managed to solve the problem by cleaning and building the project again. No more mistakes.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.