我無法讓Vaadin Navigator開始工作。出於某種原因,我總是得到一個NPE。也許你們可以幫助我。我要提到我剛剛開始與Vaadin合作。Vaadin Navigator NPE
所以這裏是代碼
@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,(類)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
}
}
這是錯誤消息我收到。我不知道我做錯了什麼。這感覺就像我檢查了所有在線教程,並複製它像他們一樣。
BTW:我使用碼頭運行(僅用於測試)
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
感謝很多網站提前
你告訴我們,堆棧跟蹤是不是一個NPE,而是「嘗試導航到未知狀態」。所以要麼堆棧跟蹤不正確,要麼搜索錯誤的地方。 –
進一步向下解決NPE – Daniel
在這種情況下,請發佈完整的堆棧跟蹤 –