重写Connector Tracker.getConnector Tracker时出现NullPointerException

时间:2014-06-05 14:47:48

标签: vaadin vaadin7

阅读本文Vaadin "A connector with id xy is already registered"后,我尝试实施Jose Luis建议的解决方案......

但是我得到了这样的痕迹:

java.lang.NullPointerException
    at com.vaadin.server.AbstractClientConnector.markAsDirty(AbstractClientConnector.java:138)
    at com.vaadin.ui.AbstractComponent.setWidth(AbstractComponent.java:844)
    at com.vaadin.ui.AbstractSingleComponentContainer.setWidth(AbstractSingleComponentContainer.java:210)
    at com.vaadin.ui.AbstractComponent.setSizeFull(AbstractComponent.java:817)
    at com.vaadin.ui.UI.<init>(UI.java:253)
    at com.vaadin.ui.UI.<init>(UI.java:238)
    at my.package.ui.MyUI.<init>(MyUI.java:72)

其中第72行对应于:

public class MyUI extends UI

有人可以帮助理解这些痕迹的原因吗? 如有必要,我可以提供更多代码。

信息:

public class MyUI extends UI {

    private final MyConnectorTracker tracker = new MyConnectorTracker(
  this);


    @Override
    public ConnectorTracker getConnectorTracker() {
      return this.tracker;
    }
}

1 个答案:

答案 0 :(得分:0)

public class MyUI extends UI {

  private MyConnectorTracker tracker;

  @Override
  public ConnectorTracker getConnectorTracker() {
    if (this.tracker == null) {
      this.tracker = new MyConnectorTracker(this);
    }
    return this.tracker;
  }
}

这解决了NullPointerException。在第一次调用UI时设置跟踪器还为时过早。