How to fix NULL object bug?

Asked

Viewed 48 times

-2

I am creating loading objects to perform unit tests, but the object I am working for is null as shown in the red arrow below, on line 39, and I can’t understand why this is happening, I need help to fix this bug!;

inserir a descrição da imagem aqui

The code is here;

public class TipoIndicioBuilder {

    private TipoIndicioEntity tipoIndicio;

    private TipoIndicioBuilder() {
    }

    public static TipoIndicioBuilder umTipoIndicio() {

        GrupoTipoIndicioEntity grupoTipoIndicio = new GrupoTipoIndicioEntity();
        grupoTipoIndicio.setCodigo(1);

        UsuarioCorporativoEntity usuarioCorporativo = new UsuarioCorporativoEntity();
        usuarioCorporativo.setCodigo(1);

        TipoIndicioBuilder builderTipoIndicio = new TipoIndicioBuilder();
        builderTipoIndicio.tipoIndicio.setCodigo(16);
        builderTipoIndicio.tipoIndicio.setNome("Acumulação2");
        builderTipoIndicio.tipoIndicio.setDescricao("Ligado2");
        builderTipoIndicio.tipoIndicio.setCriterio("oi tudo bem 2");
        builderTipoIndicio.tipoIndicio.setPrazoPadrao(20);
        builderTipoIndicio.tipoIndicio.getGrupo();
        builderTipoIndicio.tipoIndicio.getUsuarioResponsavel();
        return builderTipoIndicio;
    }

    public TipoIndicioEntity retornandoTipoIndicio() {
        return tipoIndicio;
    }

}
  • 2

    "How to fix NULL object bug?" it may seem strange to say this but... it is simple, if it is null just instantiate the object

1 answer

0


In its code, the TipoIndicioBuilderhas the variable tipoIndicio but this variable is not instantiated when you do the new TipoIndicioBuilder();.

To solve this you could do builderTipoIndicio.tipoIndicio = new TipoIndicioEntity() just before the line highlighted by the arrow in your image.

Browser other questions tagged

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