1

我正在使用 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。没有得到它背后的原因。

这可能是什么原因,任何帮助!

谢谢!

4

1 回答 1

0

如果没有更多细节,我会说:

  • v.getVisitDt()对于某些 `v` 为空
  • session.load(Resources.class, v.getReferredBy());为某些返回 null v,因此res为 null。

这可能会解决问题:

   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("?");
 }
于 2013-03-02T09:25:46.430 回答