【发布时间】:2014-07-14 21:40:22
【问题描述】:
这是 (Managed-Bean best practice) 的扩展。我写了一个类 AppProperties,它定义了类中的各种项目:
public class AppProperties implements Serializable {
private static final long serialVersionUID = 1L;
//contents of AppProperties Object
private String appRepID;
private String helpRepID;
private String ruleRepID;
private String filePath;
private Vector formNames;
//end content
private Session s;
private String serverName;
public String getAppRepID() {
return appRepID;
}
public void setAppRepID(String appRepID) {
this.appRepID = appRepID;
}
//rest if getters and setters
}
在我的 bean 中,我有以下内容:
import ca.wfsystems.core.AppProperties;
private final Map<String, AppProperties> internalMap = new HashMap<String, AppProperties>();
public ApplicationMap() {
this.buildMap(internalMap);
}
private void buildMap(Map<String, AppProperties> theMap) {
try{
AppProperties ap = null;
Session s = ExtLibUtil.getCurrentSession();
vwApps = s.getCurrentDatabase().getView("vwWFSApplications");
veCol = vwApps.getAllEntries();
ve = veCol.getFirstEntry();
tVE = null;
while (ve != null){
Vector colVal = ve.getColumnValues();
String tAppRepID = colVal.get(2).toString();
ap.setAppRepID(colVal.get(2).toString());
ap.setHelpRepID(colVal.get(3).toString());
ap.setRuleRepID(colVal.get(4).toString());
theMap.put(colVal.get(0).toString(), ap);
}
}catch(Exception e){
System.out.println(e.toString());
}finally{
Utils.recycleObjects(s,vwApps);
}
}
一切似乎都很好,除了在 ap.setAppRepID(colVal(2).toString()) 有一个编译器错误“空指针访问变量 ap 此时只能为空” setAppRepID 的代码和setHelpRepID 相同,并且 setHelpRepID 或 setRuleRepID 都没有编译器错误。我不确定问题是否出在设置 AppProperties ap = null 试图创建 AppProperties ap = new AppProperties 但它不喜欢那样。我想我真的很接近完成这项工作,但是....
感谢所有在我爬上 JAVA 斜坡时对我非常耐心的人。
【问题讨论】: