请您帮忙:
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();
返回null
,因为窗口没有默认布局,所以您在mainLayout.setWidth("100%");
中获得NPE
改变行
VerticalLayout mainLayout = (VerticalLayout) mainWindow.getContent();
VerticalLayout content = new VerticalLayout();