使用RapidClipse,我可以建立一个包含三个元素的页面。下拉字段,XdevTable和XDevfieldGroup。
下拉字段由数据库表内容填充(工作正常)
从下拉字段中选择一个值后,应填写表格(工作正常)
从XDevTable中选择一个值后,相关的行应可由字段组编辑。
在表中选择一行后,我得到了一个空指针实例:
Mai 27, 2019 4:41:19 PM com.vaadin.server.DefaultErrorHandler doDefault
SCHWERWIEGEND:
java.lang.NullPointerException
at
com.xdev.ui.entitycomponent.table.AbstractBeanTable.getSelectedItem(AbstractBeanTable.java:180)
at com.xdev.ui.masterdetail.FieldGroupMasterDetailConnection.lambda$0(FieldGroupMasterDetailConnection.java:64)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.vaadin.event.ListenerMethod.receiveEvent(ListenerMethod.java:510)
at com.vaadin.event.EventRouter.fireEvent(EventRouter.java:200)
at com.vaadin.event.EventRouter.fireEvent(EventRouter.java:163)
at com.vaadin.server.AbstractClientConnector.fireEvent(AbstractClientConnector.java:1015)
at com.vaadin.ui.AbstractField.fireValueChange(AbstractField.java:1161)
at com.vaadin.ui.AbstractField.setValue(AbstractField.java:571)
at com.vaadin.ui.AbstractSelect.setValue(AbstractSelect.java:735)
at com.vaadin.ui.AbstractField.setValue(AbstractField.java:468)
at com.vaadin.ui.AbstractSelect.changeVariables(AbstractSelect.java:547)
at com.vaadin.ui.Table.changeVariables(Table.java:2933)
at com.vaadin.server.communication.ServerRpcHandler.changeVariables(ServerRpcHandler.java:616)
at com.vaadin.server.communication.ServerRpcHandler.handleInvocation(ServerRpcHandler.java:463)
at com.vaadin.server.communication.ServerRpcHandler.handleInvocations(ServerRpcHandler.java:406)
at com.vaadin.server.communication.ServerRpcHandler.handleRpc(ServerRpcHandler.java:273)
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:1435)
at com.vaadin.server.VaadinServlet.service(VaadinServlet.java:380)
at com.xdev.communication.XdevServlet.service(XdevServlet.java:212)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:742)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:199)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:493)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:137)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:81)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:660)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343)
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:798)
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:808)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1498)
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Unknown Source)
如果我是对的,我假设存在泄漏,该泄漏标识了在表中选择的项目。但是我仍然做了RapidClipse培训中描述的内容/方式。因此,表与字段组之间的连接由表内的“ ConnectedForm”属性完成。
通过以下代码完成从下拉字段到表的连接:
private void comboBox_valueChange(final Property.ValueChangeEvent event) {
try {
Integer varMainClass = 0;
varMainClass = this.comboBox.getSelectedItem().getBean().getId();
Notification.show("Kuck a mole: ", this.comboBox.getSelectedItem().getBean().getGroupName()
, Notification.Type.ERROR_MESSAGE);
final BeanItemContainer<TGroup> mySubClasses = new BeanItemContainer<>(TGroup.class);
mySubClasses.addAll(new TGroupDAO().getAllSubClassByMainClassId(varMainClass));
this.table.setContainerDataSource(mySubClasses);
this.table.setVisibleColumns("id", "groupName");
this.table.setVisible(true);
} catch (final Exception e) {
e.printStackTrace();
final String stackTrace = Throwables.getStackTraceAsString(e);
this.textAreaErr.setValue(stackTrace);
this.textAreaErr.setVisible(true);
Notification.show("Do isch was falsch, Nachricht: ", e.getMessage(), Notification.Type.ERROR_MESSAGE);
}
}
在表中,事件valueChange只是出于测试目的的通知:
private void table_valueChange(final Property.ValueChangeEvent event) {
Notification.show("Kuck a mole: ", this.table.getSelectedItem().getBean().getGroupName()
, Notification.Type.ERROR_MESSAGE);
}
All help would be appreciated
Thanks in advance
最佳答案
我很高兴,因为我在朋友的帮助下找到了解决方案!
仍然是我的错(如预期的那样:-))。我使用了错误的容器类型:
我用了:
final BeanItemContainer<TGroup> mySubClasses = new BeanItemContainer<>(TGroup.class);
但这是错误的容器!
我应该改用:
final XdevBeanItemContainer<TGroup> mySubClasses = new XdevBeanItemContainer<>(TGroup.class);
更改后,一切正常。
我还在文档中搜索了提示,以提示我将来如何防止这种情况,但没有成功。
关于java - 如何通过RapidClipse自动生成的代码修复Null-Pointer异常,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/56328700/