NullPointerException when trying to access Bean

I’m trying to create a table based on the output given by a Bean object. However, when I attempt to call the Bean instance, I get the following error when running the code:

feb 27, 2015 4:57:34 EM org.apache.catalina.core.StandardWrapperValve invoke ALLVARLIG: Servlet.service() for servlet [com.imr.view.Imr_prototypeUI$Servlet] in context with path [/serverside_imr] threw exception [com.vaadin.server.ServiceException: java.lang.NullPointerException] with root cause java.lang.NullPointerException at com.imr.view.Imr_prototypeUI.init(Imr_prototypeUI.java:601) at com.vaadin.ui.UI.doInit(UI.java:641) at com.vaadin.server.communication.UIInitHandler.getBrowserDetailsUI(UIInitHandler.java:222) at com.vaadin.server.communication.UIInitHandler.synchronizedHandleRequest(UIInitHandler.java:74) at com.vaadin.server.SynchronizedRequestHandler.handleRequest(SynchronizedRequestHandler.java:41) at com.vaadin.server.VaadinService.handleRequest(VaadinService.java:1406) at com.vaadin.server.VaadinServlet.service(VaadinServlet.java:305) at javax.servlet.http.HttpServlet.service(HttpServlet.java:727) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122) at org.apache.tomee.catalina.OpenEJBValve.invoke(OpenEJBValve.java:44) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103) at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408) at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1070) at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:611) at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316) at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) at java.lang.Thread.run(Unknown Source) Judging from the error I get, the error when I try to call the bean (RoomBean room_bean) during initialization:

r_list = room_bean.getRooms(); // creates a list of rooms getRooms() is defined in RoomBean and I’ve declared both r_list and room_bean and annotated the latter with “@EJB” before the initialization, so I have no clue what went wrong.

Can you please show us your source for
PrototypeUI
? We can help troubleshoot your issue

We solved it by using CDI integration. I assumed before that EJB’s could be injected into a Vaadin application without additional integration as if it were a normal Java app.

@SuppressWarnings(“serial”)
@Theme(“pm”)
@PreserveOnRefresh //TODO 可以reload當時的view
public class PmUI extends UI
{
Navigator navigator;

final Logger log = LoggerFactory.getLogger(PmUI.class);

protected static final String MAINVIEW    = "main";

//TODO 取代Servlet的寫法,新寫法

@WebServlet(value = "/*", asyncSupported = true,initParams=
    {@WebInitParam(name="widgetset", value="com.jentech.pm.component.widgetset.PmWidgetset")}
)
@VaadinServletConfiguration(productionMode = true, ui = PmUI.class)
public static class Servlet extends VaadinServlet 
{

}


//TODO 這裡要處理session 導致 nullpointer的問題 ......未處理 20160122 (by Snak已處理)
//處理session 導致 nullpointer的問題 by Snak處理 20171105


@Override
protected void init(VaadinRequest request) 
{
    VaadinService service =request.getService();
    DeploymentConfiguration deploymentConf = service.getDeploymentConfiguration();
    boolean productionMode = deploymentConf.isProductionMode();
    if(productionMode){
        ProductionErrorHandler errorHandler = new ProductionErrorHandler();
        setErrorHandler(errorHandler);            
    }
    
    
    setContent(new Button("Logout", event -> {
        // Redirect this page immediately
        getPage().setLocation("/PM/");

        // Close the session
        getSession().close();
    }));
    
    // Notice quickly if other UIs are closed
    setPollInterval(3000);
    
    getPage().setTitle("PM System");
    
    // Create a navigator to control the views
    navigator = new Navigator(this, this);

    // Create and register the views
    navigator.addView("", new LoginView());
    navigator.addView(MAINVIEW, new MainView());        
    
}

I have the some question