NullPointerException:如何解决?

时间:2013-04-04 22:12:11

标签: java nullpointerexception

如何在getSubstanciasEsquemasAbertos中解析NullPointer:

public Set<SubstanciaEsquemaAbertoSoroterapia> getSubstanciasEsquemasAbertos() {

    Set<SubstanciaEsquemaAbertoSoroterapia> substancias = new LinkedHashSet<SubstanciaEsquemaAbertoSoroterapia>();

    for (EsquemaAbertoSoroterapia esquema : getEsquemasAbertosOrdenados()) {
        substancias.addAll(esquema.getSubstanciasOrdenadas());

    }
    return substancias;
}

堆栈追踪:

Caused by: org.apache.tapestry.runtime.ComponentEventException [at context:prontuario/prescricao/CriacaoPrescricao.tml, line 936, column 61]
at org.apache.tapestry.internal.structure.ComponentPageElementImpl.triggerContextEvent(ComponentPageElementImpl.java:1021)
at org.apache.tapestry.internal.structure.ComponentPageElementImpl.triggerEvent(ComponentPageElementImpl.java:934)
at org.apache.tapestry.internal.structure.InternalComponentResourcesImpl.triggerEvent(InternalComponentResourcesImpl.java:154)
at org.apache.tapestry.corelib.components.Form.onAction(Form.java:388)
at org.apache.tapestry.corelib.components.Form.dispatchComponentEvent(Form.java)
at org.apache.tapestry.internal.structure.ComponentPageElementImpl.dispatchEvent(ComponentPageElementImpl.java:851)
at org.apache.tapestry.internal.structure.ComponentPageElementImpl.triggerContextEvent(ComponentPageElementImpl.java:1004)
... 79 more

引起:java.lang.NullPointerException     at br.gov.mg.fhemig.sighfase2.entidade.prontuario.prescricao.ItemPrescricaoSoroterapia.getSubstanciasEsquemasAbertos(ItemPrescricaoSoroterapia.java:442)     在br.gov.mg.fhemig.sighfase2.web.pages.prontuario.prescricao.CriacaoPrescricao.sucesso(CriacaoPrescricao.java:1480)     at br.gov.mg.fhemig.sighfase2.web.pages.prontuario.prescricao.CriacaoPrescricao.dispatchComponentEvent(1 CriacaoPrescricao.java)     at org.apache.tapestry.internal.structure.ComponentPageElementImpl.dispatchEvent(ComponentPageElementImpl.java:843)     at org.apache.tapestry.internal.structure.ComponentPageElementImpl.triggerContextEvent(ComponentPageElementImpl.java:1004)     ... 85更多

1 个答案:

答案 0 :(得分:2)

getEsquemasAbertosOrdenados()或其中一个esquema.getSubstanciasOrdenadas()可能会返回null。如果不查看实际的堆栈跟踪就很难分析,你应该把它作为问题的一部分发布。