A connector with id # is already registered!

I am writing a simple application and can not solve this exception:

Caused by: java.lang.RuntimeException: A connector with id 9 is already registered!
at com.vaadin.ui.ConnectorTracker.registerConnector(ConnectorTracker.java:133) ~[vaadin-server-7.1.6.jar:7.1.6]

at com.vaadin.server.AbstractClientConnector.attach(AbstractClientConnector.java:578) ~[vaadin-server-7.1.6.jar:7.1.6]

at com.vaadin.ui.AbstractComponent.attach(AbstractComponent.java:571) ~[vaadin-server-7.1.6.jar:7.1.6]

at com.vaadin.server.AbstractClientConnector.attach(AbstractClientConnector.java:583) ~[vaadin-server-7.1.6.jar:7.1.6]

at com.vaadin.ui.AbstractComponent.attach(AbstractComponent.java:571) ~[vaadin-server-7.1.6.jar:7.1.6]

at com.vaadin.ui.AbstractComponent.setParent(AbstractComponent.java:478) ~[vaadin-server-7.1.6.jar:7.1.6]

at com.vaadin.ui.AbstractSingleComponentContainer.setContent(AbstractSingleComponentContainer.java:137) ~[vaadin-server-7.1.6.jar:7.1.6]

at com.vaadin.ui.UI.setContent(UI.java:1158) ~[vaadin-server-7.1.6.jar:7.1.6]

at com.vaadin.navigator.Navigator$SingleComponentContainerViewDisplay.showView(Navigator.java:224) ~[vaadin-server-7.1.6.jar:7.1.6]

at com.vaadin.navigator.Navigator.navigateTo(Navigator.java:568) ~[vaadin-server-7.1.6.jar:7.1.6]

at com.vaadin.navigator.Navigator.navigateTo(Navigator.java:526) ~[vaadin-server-7.1.6.jar:7.1.6]

at com.xxx.xxx.view.LoginView$1.componentEvent(LoginView.java:34) ~[main/:?]

My application setup: Jetty 8 running VaadinServlet (no Spring or any other framework but Vaadin). Main UI only has one Navigator object.
Scenario to reproduce the problem:

  1. User logs in (goes from the Login View to Main View)
  2. User logs out (session closed, new Session and UI is created)
  3. User logs in again - exception happens when he tries to go to the Main View.
    Exception does not happen if the MainView only has static components (private static final Label hello = new Label():wink: which are then added the the layout in the instance constructor.

Could anyone help me with this issue?

You should generally NEVER have static components in your applications…
Once a Component is attached it belongs to its current UI, and should not be used in another UI.
Replace


 private static final Label hello = new Label();

With


 private final Label hello = new Label();

I wish, but that does not work. Hence the question. I have explained that in the initial post. When I tried to use local variables (not even instance fields) Vaadin was throwing that exception

Actually, you were correct. I had a Menu object which was a singleton. That is odd that the error was throwed while I was adding other components, not the menu.

Anyway, thanks!

Components are given an id the first time they are attached to a UI. The ids are sequential and each UI has a private id counter. UIs also assume that components are never moved from one UI to another, so each attached component got its id from the current parent. Thus, the following may happen:

UI 1:
addComponent(someComponent1); // someComponent1 gets id 1
addComponent(mySharedMenu); // mySharedMenu gets id 2

UI2:
addComponent(someComponent2); // someComponent2 gets id 1
addComponent(mySharedMenu); // mySharedMenu already has an id (given by UI1) so UI2’s counter is not incremented!
addComponent(someComponent3); // someComponent3 gets id 2!

On the last line, things go boom due to someComponent3 getting the same id that’s already in use by mySharedMenu.