Many months ago, I encountered a NullPointerException when my simple UI used a Navigator to navigate from LoginView to MainView when the user hit the “OK” button (i.e. the buttonClick() method in LoginView did a Navigator.navigateTo(“MainView”).
At that time I was running 7.5.1 - and since nobody responded, I worked around the problem by overriding MainView’s “detach()” method with one that doesn’t do anything. Since I began encountering the same NullPointerException elsewhere in my expanding UI, I decided to give the latest Vaadin (7.6.4) a try to see if the above problem was magically fixed - it wasn’t Same NullPointerException (slightly different line count). This leads me to believe I’m doing something fundamentally wrong. Any enlightenment would be very much appreciated.
My UI class, in its “init(VaadinRequest)” method simply creates a Navigator and calls “addView(”“, new LoginView())” and “addView(“MainView”, new MainView())”.
My “MainView” (and most of my other components) extends CustomLayout and implements View. I add my UI components in the constructor via “addComponent(Component, String)”.
As soon as I navigateTo(“MainView”) the NullPointerException below happens. I just found a similar bug report in which the Vaadin engineer suggests running the server with “-ea” option. When I do that, I see the warning:
WARNING: com.lenovo.lsat.ui.LSAT_UI(0) claims that com.lenovo.lsat.ui.MainView(6) is its child, but the child claims (null) is its parent.
Ok, that’s helpful - but why/how do I set the parent for MainView? It’s managed by Navigator - I thought it handled the attaching (reparenting) of the View to the UI as needed? Here’s the full constructor of my MainView:
[code]
public class MainView extends CustomLayout implements View {
private static final String MENUBAR_WIDTH = “60%”;
private LSAT_UI ui;
private MenuBar menubar = new MenuBar();
private MenuBar.MenuItem adminMenu;
private MenuBar.MenuItem productsMenu;
private final Label versionLabel = new Label("SAT " + Constants.SAT_VERSION + " - (c) 2015 Lenovo All Rights Reserved");
public MainView(LSAT_UI uiIn) {
super("mainViewLayout");
ui = uiIn;
menubar.addStyleName("menubar");
menubar.setWidth(MENUBAR_WIDTH);
createMenus(menubar);
addComponent(menubar, "menubar");
addComponent(versionLabel, "versionLabel");
}
…
[/code]And below is the NullPointerException:
java.lang.NullPointerException
at com.vaadin.server.AbstractClientConnector.detach(AbstractClientConnector.java:641)
at com.vaadin.ui.AbstractComponent.detach(AbstractComponent.java:692)
at com.vaadin.server.AbstractClientConnector.detach(AbstractClientConnector.java:636)
at com.vaadin.ui.AbstractComponent.detach(AbstractComponent.java:692)
at com.vaadin.ui.AbstractComponent.setParent(AbstractComponent.java:574)
at com.vaadin.ui.AbstractSingleComponentContainer.setContent(AbstractSingleComponentContainer.java:150)
at com.vaadin.ui.UI.setContent(UI.java:1312)
at com.vaadin.navigator.Navigator$SingleComponentContainerViewDisplay.showView(Navigator.java:228)
at com.vaadin.navigator.Navigator.navigateTo(Navigator.java:611)
at com.vaadin.navigator.Navigator.navigateTo(Navigator.java:573)
at com.lenovo.lsat.ui.LoginView$1.buttonClick(LoginView.java:58)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.vaadin.event.ListenerMethod.receiveEvent(ListenerMethod.java:508)
at com.vaadin.event.EventRouter.fireEvent(EventRouter.java:198)
at com.vaadin.event.EventRouter.fireEvent(EventRouter.java:161)
at com.vaadin.server.AbstractClientConnector.fireEvent(AbstractClientConnector.java:1008)
at com.vaadin.ui.Button.fireClick(Button.java:377)
at com.vaadin.ui.Button$1.click(Button.java:54)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.vaadin.server.ServerRpcManager.applyInvocation(ServerRpcManager.java:158)
at com.vaadin.server.ServerRpcManager.applyInvocation(ServerRpcManager.java:118)
at com.vaadin.server.communication.ServerRpcHandler.handleInvocations(ServerRpcHandler.java:408)
at com.vaadin.server.communication.ServerRpcHandler.handleRpc(ServerRpcHandler.java:273)
at com.vaadin.server.communication.PushHandler$2.run(PushHandler.java:149)
at com.vaadin.server.communication.PushHandler.callWithUi(PushHandler.java:243)
at com.vaadin.server.communication.PushHandler.onMessage(PushHandler.java:503)
at com.vaadin.server.communication.PushAtmosphereHandler.onMessage(PushAtmosphereHandler.java:88)
at com.vaadin.server.communication.PushAtmosphereHandler.onRequest(PushAtmosphereHandler.java:78)
at org.atmosphere.cpr.AsynchronousProcessor.action(AsynchronousProcessor.java:199)
at org.atmosphere.cpr.AsynchronousProcessor.suspended(AsynchronousProcessor.java:107)
at org.atmosphere.container.Servlet30CometSupport.service(Servlet30CometSupport.java:66)
at org.atmosphere.cpr.AtmosphereFramework.doCometSupport(AtmosphereFramework.java:2075)
at org.atmosphere.websocket.DefaultWebSocketProcessor.dispatch(DefaultWebSocketProcessor.java:571)
at org.atmosphere.websocket.DefaultWebSocketProcessor$3.run(DefaultWebSocketProcessor.java:333)
at org.atmosphere.util.VoidExecutorService.execute(VoidExecutorService.java:101)
at org.atmosphere.websocket.DefaultWebSocketProcessor.dispatch(DefaultWebSocketProcessor.java:328)
at org.atmosphere.websocket.DefaultWebSocketProcessor.invokeWebSocketProtocol(DefaultWebSocketProcessor.java:425)
at org.atmosphere.container.JSR356Endpoint$1.onMessage(JSR356Endpoint.java:213)
at org.atmosphere.container.JSR356Endpoint$1.onMessage(JSR356Endpoint.java:210)
at org.apache.tomcat.websocket.WsFrameBase.sendMessageText(WsFrameBase.java:393)
at org.apache.tomcat.websocket.WsFrameBase.processDataText(WsFrameBase.java:494)
at org.apache.tomcat.websocket.WsFrameBase.processData(WsFrameBase.java:289)
at org.apache.tomcat.websocket.WsFrameBase.processInputBuffer(WsFrameBase.java:130)
at org.apache.tomcat.websocket.server.WsFrameServer.onDataAvailable(WsFrameServer.java:60)
at org.apache.tomcat.websocket.server.WsHttpUpgradeHandler$WsReadListener.onDataAvailable(WsHttpUpgradeHandler.java:203)
at org.apache.coyote.http11.upgrade.AbstractServletInputStream.onDataAvailable(AbstractServletInputStream.java:198)
at org.apache.coyote.http11.upgrade.AbstractProcessor.upgradeDispatch(AbstractProcessor.java:96)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:668)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1500)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1456)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)