请您帮忙:
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
因为 Window 没有默认布局,因此您在 mainLayout.setWidth("100%"中得到一个 NPE );
换行
VerticalLayout mainLayout = (VerticalLayout) mainWindow.getContent();
至
VerticalLayout content = new VerticalLayout();
它应该可以工作。
关于java - com.vaadin.server.ServiceException : java. lang.NullPointerException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31578628/