我有一個簡單的問題,當我調用一個託管bean方法返回一個列表時,爲什麼總是得到一個NPE。我在我看來使用了primefaces嚮導組件。例如可以sometone告訴我,這兩者之間的區別:調用託管bean方法返回一個NPE
不起作用:
public List<RequiredParam> getRequiredFields() {
if(!this.sdeCommand.getActions().isEmpty() &&this.action!=null &&!this.action.equals("")){
for(CommandAction act:this.sdeCommand.getCommandActions()){
if(act.getActionName().equalsIgnoreCase(this.action)){
this.requiredFields.addAll(act.getFields());
}
}
}
return this.requiredFields;
}
但是這個工程:
public List<RequiredParam> getRequiredFields() {
return this.requiredFields;
}
的觀點:
<c:forEach items="${gdsiGeodataBean.requiredFields}" var="reqs">
<h:outputLabel for="#{reqs.name}" value="#{reqs.name}:* " />
</c:forEach>
錯誤信息:
java.lang.NullPointerException
com.tsystems.appbeans.GdsiGeodataBean.getRequiredFields(GdsiGeodataBean.java:103)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
java.lang.reflect.Method.invoke(Method.java:597)
javax.el.BeanELResolver.getValue(BeanELResolver.java:62)
com.sun.faces.el.DemuxCompositeELResolver._getValue(DemuxCompositeELResolver.java:176)
com.sun.faces.el.DemuxCompositeELResolver.getValue(DemuxCompositeELResolver.java:203)
org.apache.el.parser.AstValue.getValue(AstValue.java:118)
...
我的觀點:
顯然,你的一些bean的屬性是'null'。仔細檢查你是否已經正確實例化了所有的'List'屬性 – 2012-01-05 11:38:14
@ Mr.J4mes,謝謝其中的一個屬性爲null。我正在使用一個嚮導,並且已經在前一個選項卡中設置了該屬性。不知何故該物業失去了價值。 – algone 2012-01-05 17:15:24