【问题标题】:Null Pointer exception on Indexed Container Vaadin索引容器 Vaadin 上的空指针异常
【发布时间】:2013-03-02 09:11:06
【问题描述】:

我正在使用 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。不明白背后的原因。

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

谢谢!

【问题讨论】:

  • 请发布堆栈跟踪

标签: java hibernate vaadin


【解决方案1】:

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

  • v.getVisitDt() 对于某些 `v`` 为空
  • session.load(Resources.class, v.getReferredBy()); 为某些 v 返回 null,因此 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("?");
 }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-06-07
    • 2016-08-27
    • 2018-07-16
    • 2021-01-19
    • 2019-07-18
    • 2013-08-12
    • 2015-03-27
    相关资源
    最近更新 更多