0
I have the following method in the Logincontroller class
@RequestMapping(value = "/usuarioEntidade", consumes = MediaType.APPLICATION_JSON_UTF8_VALUE, method = RequestMethod.POST)
public Resposta usuarioEntidade(@RequestBody EntidadesAdministradores usuarioEntidade) throws ServletException {
EntidadesAdministradores entAdministradoresAutenticado = eaService.buscarUsuarioEntidade(usuarioEntidade.getUsuarioAdministrador());
usuarioEntidade = entAdministradoresAutenticado;
Long us = usuarioEntidade.getEntidade().getIdEntidade();
return new Resposta (us);
}
public class Resposta {
public Long us;
public Resposta(Long us) {
this.us = us;
}
public Long getUs() {
return us;
}
}
I have debugged and the return of the method is coming what I want, a type id Long.
Passing the return of this method , us, for the Distritocontroller class, when I call the request /distritos have a mistake of java.lang.NullPointerException
Distritocontroller
@Autowired
DistritosService distritosService;
Resposta resp;
@RequestMapping(method = RequestMethod.GET, value = "/distritos", produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<Collection<Distritos>> buscarTodosDistritos(Long usuarioEntidade) throws ServletException {
usuarioEntidade = resp.getUs();
Collection<Distritos> distritosBuscados = distritosService.buscarFiltro(usuarioEntidade);
return new ResponseEntity<>(distritosBuscados, HttpStatus.OK);
}
The stacktrace of
NullPointerExceptionpoints to the line ofCollection<Distritos> distritosBuscados = distritosService.buscarFiltro(usuarioEntidade);?– Victor Stafusa
points to this line
controller.DistritosController.buscarTodosDistritos(DistritosController.java:44) ~[classes/:na]that isusuarioEntidade = resp.getUs();– Eduardo Krakhecke
That is to say,
respisnull. How does the classLoginControllerflame toDistritoController? Where therespcould be being set?– Victor Stafusa
Useful reading: https://answall.com/q/63617/64969
– Jefferson Quesado