我是vaadin的新手,我正在构建一个需要使用多个视图的应用, 这里是代码片段和堆栈跟踪, 我检查了构建路径,以确保它不是一个依赖问题,谷歌搜索没有给出有用的答案或线索
Button button = new Button("Login", new Button.ClickListener(){
@Override
public void buttonClick(ClickEvent event){
layout.addComponent(new Label("establishing connection ..."));
getUI().getNavigator().navigateTo("");
}
});
@Override
public void enter(ViewChangeEvent event) {
// TODO Auto-generated method stub
}
}
这是导航器类:
public class navigator extends LoInf {
Navigator navigator;
public static final String MAINVIEW = "main";
//public static final String view = "interface";
@Override
protected void init(VaadinRequest request) {
getPage().setTitle("login");
navigator = new Navigator(this,this);
navigator.addView(MAINVIEW, new LoInf());
navigator.addView("", RMQcl.class);
}
public static void navigateTo(String mainview2) {
}
}
这是堆栈跟踪
oct. 24, 2017 3:05:30 PM com.vaadin.server.DefaultErrorHandler doDefault
GRAVE:
java.lang.NullPointerException
at my.vaadin.Project.LoInf$1.buttonClick(LoInf.java:43)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at com.vaadin.event.ListenerMethod.receiveEvent(ListenerMethod.java:510)
at com.vaadin.event.EventRouter.fireEvent(EventRouter.java:211)
at com.vaadin.event.EventRouter.fireEvent(EventRouter.java:174)
at com.vaadin.server.AbstractClientConnector.fireEvent(AbstractClientConnector.java:1033)
at com.vaadin.ui.Button.fireClick(Button.java:370)
at com.vaadin.ui.Button$1.click(Button.java:57)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at com.vaadin.server.ServerRpcManager.applyInvocation(ServerRpcManager.java:155)
at com.vaadin.server.ServerRpcManager.applyInvocation(ServerRpcManager.java:116)
at com.vaadin.server.communication.ServerRpcHandler.handleInvocation(ServerRpcHandler.java:445)
at com.vaadin.server.communication.ServerRpcHandler.handleInvocations(ServerRpcHandler.java:410)
at com.vaadin.server.communication.ServerRpcHandler.handleRpc(ServerRpcHandler.java:274)
at com.vaadin.server.communication.UidlRequestHandler.synchronizedHandleRequest(UidlRequestHandler.java:90)
at com.vaadin.server.SynchronizedRequestHandler.handleRequest(SynchronizedRequestHandler.java:41)
at com.vaadin.server.VaadinService.handleRequest(VaadinService.java:1568)
at com.vaadin.server.VaadinServlet.service(VaadinServlet.java:381)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:845)
at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1689)
at org.eclipse.jetty.websocket.server.WebSocketUpgradeFilter.doFilter(WebSocketUpgradeFilter.java:225)
at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1676)
at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:581)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:143)
at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:548)
at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:226)
at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1174)
at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:511)
at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:185)
at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1106)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)
at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:213)
at org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:119)
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:134)
at org.eclipse.jetty.server.Server.handle(Server.java:524)
at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:319)
at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:253)
at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:273)
at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:95)
at org.eclipse.jetty.io.SelectChannelEndPoint$2.run(SelectChannelEndPoint.java:93)
at org.eclipse.jetty.util.thread.strategy.ExecuteProduceConsume.executeProduceConsume(ExecuteProduceConsume.java:303)
at org.eclipse.jetty.util.thread.strategy.ExecuteProduceConsume.produceConsume(ExecuteProduceConsume.java:148)
at org.eclipse.jetty.util.thread.strategy.ExecuteProduceConsume.run(ExecuteProduceConsume.java:136)
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:671)
at org.eclipse.jetty.util.thread.QueuedThreadPool$2.run(QueuedThreadPool.java:589)
at java.lang.Thread.run(Thread.java:745)
似乎无法弄清问题是什么, 帮助赞赏
[更新] 这是我试图导航到的课程:
@SpringUI
public class RMQcl extends RMQ implements UserRep,View{
UserRep repo;
Grid <UserModel> grid;
TextField filter = new TextField();
UserEdit editor;
Button addnew;
UserModel User;
Binder<UserModel> binder = new Binder<>(UserModel.class);
final VerticalLayout layout = new VerticalLayout(filter,grid);
@Autowired
public RMQcl(UserRep repo,UserEdit editor){
this.repo = repo;
this.grid = new Grid<>(UserModel.class);
this.editor = editor;
this.filter = new TextField();
binder.bindInstanceFields(this);
this.addnew = new Button("New User",FontAwesome.PLUS);
logout = new Button("Logout");
logout.addClickListener(new ClickListener() {
private static final long serialVersionUID = 1L;
public void buttonClick(ClickEvent event) {
getUI().getNavigator().navigateTo(navigator.MAINVIEW);
}
});
}
//@Override
public void init(VaadinRequest request){
layout.addComponents(grid);
setContent(layout);
listUsers(null);
binder.setBean(User);
HorizontalLayout actions = new HorizontalLayout(filter,addnew);
VerticalLayout Layout = new VerticalLayout(actions,grid,editor);
setContent(Layout);
grid.setHeight(300,Unit.PIXELS);
grid.setColumns("id","firsname","lastname");
filter.setPlaceholder("Filtering by lastname");
filter.setValueChangeMode(ValueChangeMode.LAZY);
filter.addValueChangeListener(e->listUsers(e.getValue()));
grid.asSingleSelect().addValueChangeListener(e->{
editor.editUser(e.getValue());
});
addnew.addClickListener(e -> editor.editUser(new UserModel("", "")));
editor.setChangeHandler(()->{
editor.setVisible(false);
listUsers(filter.getValue());
});
listUsers(null);
}
private void setContent(VerticalLayout layout2) {
// TODO Auto-generated method stub
}
private void listUsers(String Filter) {
if(StringUtils.isEmpty(Filter)){
grid.setItems(repo.findAll());
}else{
grid.setItems(repo.findByLastNameStartsWithIgnoreCase(Filter));
}
filter.setPlaceholder("Filter by last name");
filter.setValueChangeMode(ValueChangeMode.LAZY);
filter.addValueChangeListener(e-> listUsers(e.getValue()));
setContent(layout);
}