Why am I getting an internal server error?

可紊 提交于 2021-01-29 09:13:39

问题


I'm creating a REST web service with Spring, but I'm getting a internal server error and don't understand why. I have a List of DoenteIdentidade's, this is the structure of the DoenteIdentidade

{
    "id": 1,
    "nome": "Highway Ergonomic",
    "dataNasc": "2020-01-10",
    "altura": 31098,
    "morada": "moratorium pixel withdrawal",
    "codPost": "Mississippi embrace Developer",
    "freguesia": "synthesize Idaho compress",
    "nif": 49379,
    "medFam": "Poland",
    "sexo": "Masculino",
    "telef": 3142,
    "telef2": 89576,
    "docId": 63641,
    "nBenef": 47537,
    "nUtente": 31435,
    "numProcHosp": 56327,
    "doente": {
        "id": 1,
        "situacao": "StatusDP",
        "horarioDoentes": null,
        "doenteDiagnosticoSocials": null,
        "doenteRegistosIntervencoes": null,
        "doenteHistMovimentos": null,
        "doenteContactosOutros": null,
        "turnos": {
            "id": 1,
            "nome": "Metal"
        }
    },
    "subsistemas": {
        "id": 3,
        "gidNome": "Small",
        "gidCode": 14001,
        "subSisGrupo": null
    },
    "centroSaude": null,
    "hospRef": null,
    "pais": null,
    "aces": null
}

As you can see there is a object inside called Doente, what I'm trying to do is extract all the Doente objects contained inside all the DoenteIdentidade of this list to a List of Doente's.

Here is a snippet of the code I wrote for this goal, for some reason I'm getting a internal server error when I try to add to the List of Doente's.

else if(situacao == null && subSistema != null && t == null){
        List<DoenteIdentidade> doenteIdentidades = doenteIdentidadeRepository.findAllBySubsistemasId(subSistema);
        List<Doente> doentes2=null;
        for (DoenteIdentidade doenteIdentidade: doenteIdentidades) {
            doentes2.add(doenteIdentidade.getDoente());
        }
        return doentes2;
    }

Any help is very welcomed.


回答1:


doentes2 is null when you are adding your doente. Try instead:

List<Doente> doentes2 = new ArrayList<>();


来源:https://stackoverflow.com/questions/59769786/why-am-i-getting-an-internal-server-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!