gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 22:12:41 27 4
gpt4 key购买 nike

请您帮忙:

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/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com