I’ve been searching in the Internet about this error with no result. I’m lost with it. Anyone can help with it?
.
.
.
TipoEstablecimientoHotel tipoEstablecimiento = null;
.
.
.
.
try{
tipoEstablecimiento.setCodigo(""); <--- Line with the error.
}catch (Exception e){
System.out.println(e.getMessage());
}
.
.
.
Of course I have the imports that I need (I mean for TipoEstablecimiento), and it marks that line with the corresponding warning.
Thanks in advance.
You didn’t show us enough code, but I’d go with the error you got. You don’t initialize the variable between assigning null to it and calling its
setCodigomethod so you’ll surely get a NullPointerException (you cannot dereference a null object). Make sure you instantiate it before using it by calling its constructor, something like: