com.vaadin.server.ServiceException: java.lang.NullPointerException

com.vaadin.server.ServiceException: java.lang.NullPointerException

请你帮忙:

com.vaadin.server.ServiceException: java.lang.NullPointerException

它崩溃了 mainLayout.setWidth("100%");

//***************************************
private void createUI() {
    final Window mainWindow = new Window("Raspberry Pi GPIO Control Center");
    VerticalLayout mainLayout = (VerticalLayout) mainWindow.getContent();
    setContent(mainLayout);
    System.out.println("1");
    mainLayout.setWidth("100%");
    System.out.println("2");
    mRefresher = new Refresher();
    mRefresher.setRefreshInterval(RefreshIntervalMilliSec);
    mRefresher.addListener(new RefreshListener() {
        private static final long serialVersionUID = 1L;

        @Override
        public void refresh(Refresher source) {
            periodicRefresh();
        }
    });
    mainLayout.addComponent(mRefresher);
    createTitle(mainLayout);
    mMainContentLayout = new VerticalLayout();
    mMainContentLayout.setWidth("100%");
    mainLayout.addComponent(mMainContentLayout);
    mainLayout.setComponentAlignment(mMainContentLayout, Alignment.MIDDLE_CENTER);
    createUIForUser();
}
//***************************************

mainWindow.getContent(); returns null 因为 Window 没有默认布局,所以你在 mainLayout.setWidth("100%");

中得到一个 NPE

换行

 VerticalLayout mainLayout = (VerticalLayout) mainWindow.getContent();

VerticalLayout content = new VerticalLayout();

它应该可以工作。