我正在使用vaadin的FilterTable插件。 我在下面的代码中得到一个NullPointerException,但无法找到原因。
cont = new IndexedContainer()
cont.addContainerProperty("Patient", String.class, null);
cont.addContainerProperty("Date Of Service", String.class,null);
cont.addContainerProperty("Provider", String.class, null);
Session session = HibernateUtil.getSessionFactory().openSession();
Iterator<?> iterator = session.createQuery("FROM ConvertVisitToBillingV WHERE ready_for_billing = '0'").list().iterator();
while(iterator.hasNext()){
ConvertVisitToBillingV var = (ConvertVisitToBillingV) iterator.next();
Visits v = (Visits) session.load(Visits.class, var.getVisitId());
Appointments app = (Appointments)session.load(Appointments.class, v.getAppointmentId());
t_id= var.getVisitId();
cont.addItem(t_id);
Resources res = (Resources)session.load(Resources.class, v.getReferredBy());
cont.getContainerProperty(t_id, "Patient").setValue(var.getFirstName() + " " + var.getLastName());
cont.getContainerProperty(t_id, "Date Of Service").setValue(new SimpleDateFormat("MM/dd/yyyy").format(v.getVisitDt()));
cont.getContainerProperty(t_id, "Provider").setValue(res.getResourceFirstName()+" "+res.getResourceLastName());
}
当它执行“cont.getContainerProperty(t_id,property).setValue()”行时 它偶尔会抛出NullPointerException。没有理由背后的原因。
这可能是什么原因,任何帮助!
谢谢!
答案 0 :(得分:0)
如果没有更多细节,我会说:
v.getVisitDt()
为空
session.load(Resources.class, v.getReferredBy());
为某些v
返回null,因此res
为空。这可能会解决问题:
cont.getContainerProperty(t_id, "Patient").setValue(var.getFirstName() + " " + var.getLastName());
if(v.getVisitDt()!=null){
cont.getContainerProperty(t_id, "Date Of Service").setValue(new SimpleDateFormat("MM/dd/yyyy").format(v.getVisitDt()));
} else {
cont.getContainerProperty(t_id, "Date Of Service").setValue("?");
}
if(res!=null){
cont.getContainerProperty(t_id, "Provider").setValue(res.getResourceFirstName()+" "+res.getResourceLastName());
else{
cont.getContainerProperty(t_id, "Provider").setValue("?");
}