gpt4 book ai didi

java - Vaadin 导航器 NPE

转载 作者:行者123 更新时间:2023-12-02 03:51:42 26 4
gpt4 key购买 nike

我无法让 Vaadin Navigator 开始工作。出于某种原因,我总是得到 NPE。也许你们可以帮助我。我不得不提一下,我刚刚开始使用 Vaadin。

所以这是代码

@Theme("mytheme")
@Widgetset("de.javahouse.jobwiz.MyAppWidgetset")
public class BasicInformation extends UI {

public static final String VIEW_NAME_BASIC = "basic";
public static final String VIEW_NAME_ADV = "advanced";

private Navigator nav;
private static final long serialVersionUID = 2548993131483469880L;

@Override
protected void init(VaadinRequest vaadinRequest) {

HorizontalLayout layout = generateContent();
nav = new Navigator(this,this);
nav.addView(VIEW_NAME_ADV, new AdditionalInformation());

//这也不起作用//nav.addView(VIEW_NAME_BASIC, (Class) BasicInformation.class);

    setContent(layout);


}

private HorizontalLayout generateContent(){

HorizontalLayout layout = new HorizontalLayout();

FormLayout form = new FormLayout();

OptionGroup single = new OptionGroup("Gender");
single.addItems("Male", "Female");
form.addComponent(single);

TextField tfFirstname = new TextField("First Name");
tfFirstname.setRequired(true);
form.addComponent(tfFirstname);

TextField tfFamilyName = new TextField("Family Name");
tfFamilyName.setRequired(true);
form.addComponent(tfFamilyName);

TextField tfEmail = new TextField("E-mail");
tfEmail.setRequired(true);
form.addComponent(tfEmail);

Button btSave = new Button("Save and Proceed");
btSave.addClickListener(new Button.ClickListener() {

private static final long serialVersionUID = 1L;

@Override
public void buttonClick(ClickEvent event) {
nav.navigateTo(VIEW_NAME_ADV);
}
});
form.addComponent(btSave);

layout.addComponent(form);



return layout;
}

@WebServlet(urlPatterns = "/*", name = "MyUIServlet", asyncSupported = true)
@VaadinServletConfiguration(ui = BasicInformation.class, productionMode = false)
public static class MyUIServlet extends VaadinServlet {

/**
*
*/
private static final long serialVersionUID = 1L;
}

}

public class AdditionalInformation extends VerticalLayout implements View {

private static final long serialVersionUID = 1578488973205488083L;

public AdditionalInformation(){
Label lbl = new Label("Whatever");
addComponent(lbl);

}

@Override
public void enter(ViewChangeListener.ViewChangeEvent event) {
// TODO Auto-generated method stub

}

}

这是我收到的错误消息。我不知道我做错了什么。感觉就像我检查了所有在线教程并复制了它,就像它们一样。

顺便说一句:我正在使用 jetty 来运行该网站(仅用于测试)

javax.servlet.ServletException: com.vaadin.server.ServiceException: java.lang.IllegalArgumentException: Trying to navigate to an unknown state '' and an error view provider not present
at com.vaadin.server.VaadinServlet.service(VaadinServlet.java:366)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:769)
at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1667)
at org.eclipse.jetty.websocket.server.WebSocketUpgradeFilter.doFilter(WebSocketUpgradeFilter.java:172)
at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1650)
at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:583)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:143)
at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:577)
at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:223)
at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1125)
at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:515)
at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:185)
at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1059)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)
at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:215)
at org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:110)
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:97)
at org.eclipse.jetty.server.Server.handle(Server.java:497)
at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:311)
at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:248)
at org.eclipse.jetty.io.AbstractConnection$2.run(AbstractConnection.java:540)
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:610)
at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:539)
at java.lang.Thread.run(Thread.java:745)
Caused by: com.vaadin.server.ServiceException: java.lang.IllegalArgumentException: Trying to navigate to an unknown state '' and an error view provider not present
at com.vaadin.server.VaadinService.handleExceptionDuringRequest(VaadinService.java:1464)
at com.vaadin.server.VaadinService.handleRequest(VaadinService.java:1421)
at com.vaadin.server.VaadinServlet.service(VaadinServlet.java:364)
... 24 more
Caused by: java.lang.IllegalArgumentException: Trying to navigate to an unknown state '' and an error view provider not present
at com.vaadin.navigator.Navigator.navigateTo(Navigator.java:575)
at com.vaadin.ui.UI.doInit(UI.java:687)
at com.vaadin.server.communication.UIInitHandler.getBrowserDetailsUI(UIInitHandler.java:214)
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:1409)
... 25 more

提前非常感谢

最佳答案

有一个thread in vaadin forum about this issue

我遇到过这个问题,解决方法是模拟一个空的引用 View 。对于你的情况,我建议你设置

public static final String VIEW_NAME_ADV = ""; // force to empty string

否则,相同的 vaadin 线程表明修复错误 View 实例可以是一个修复

this.navigator.setErrorView(myView);

关于java - Vaadin 导航器 NPE,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35828527/

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