Java vaadin表中的NullPointerException?

Java vaadin表中的NullPointerException?,java,vaadin,vaadin7,Java,Vaadin,Vaadin7,我对瓦丁桌有点问题。当我更改显示的值行时,返回NullPointerException,我不知道为什么。在vaadin book第5章表中,当这个问题发生时,有一个方法setNullSelectionLowed(false),但对我来说仍然不起作用 // Table configs Table tabela = new Table(); tabela.setSizeFull(); tabela.addContainerProperty("Aperfeiçoamento", Stri

我对瓦丁桌有点问题。当我更改显示的值行时,返回NullPointerException,我不知道为什么。在vaadin book第5章表中,当这个问题发生时,有一个方法setNullSelectionLowed(false),但对我来说仍然不起作用

// Table configs
Table tabela = new Table();
tabela.setSizeFull();       
tabela.addContainerProperty("Aperfeiçoamento", String.class, null);
tabela.addContainerProperty("Entidade", String.class, null);
tabela.addContainerProperty("Início", String.class, null);
tabela.addContainerProperty("Conclusão", String.class, null);   
tabela.setNullSelectionAllowed(false);
tabela.setImmediate(true);
tabela.setSelectable(true);
tabela.setColumnReorderingAllowed(false);
tabela.addValueChangeListener(this);

@Override
public void valueChange(ValueChangeEvent event) {
    /** preenche os campos do formulario com o id do aperfeicoamento */
    String id = event.getProperty().getValue().toString();
    List<Aperfeicoamento> lista = new AperfeicoamentoDAO().getAperfeicoamentoById(Integer.parseInt(id));
    if(!lista.isEmpty()){
        try{
            for(Aperfeicoamento apf : lista){
                aperfeicoamento.setValue(apf.getAperfeicoamento());
                entidadeEnsino.setValue(apf.getEntidadeEnsino());
                cidade.setValue(apf.getCidade());
                comboEstado.setValue(apf.getEstado());
                inicio.setValue(new SimpleDateFormat("dd/MM/yyyy").parse(apf.getInicio()));
                conclusao.setValue(!apf.getConclusao().isEmpty() ? new SimpleDateFormat("dd/MM/yyyy").parse(apf.getConclusao()) : null);    
            }
        }catch(ParseException e){
            e.printStackTrace();
        }
    }
}

// DAO
/** retorna uma lista de perfeicoamento por id e cpf */
public List<Aperfeicoamento> getAperfeicoamentoById(Integer id){
    List<Aperfeicoamento> lista = new ArrayList<Aperfeicoamento>();     
    try{
        PreparedStatement stm = this.con.prepareStatement("SELECT * FROM aperfeicoamento WHERE idAperfeicoamento = ? AND cpf = ?");         
        stm.setInt(1, id);
        stm.setString(2, SessionCurriculum.getCpfInSession());
        ResultSet rs = stm.executeQuery();
        if(rs.next()){
            Aperfeicoamento apf = new Aperfeicoamento();
            apf.setIdAperfeicoamento(rs.getInt("idAperfeicoamento"));
            apf.setAperfeicoamento(rs.getString("aperfeicoamento"));
            apf.setEntidadeEnsino(rs.getString("entidadeensino"));
            apf.setCidade(rs.getString("cidade"));
            apf.setEstado(rs.getString("estado"));
            apf.setInicio(new ControlaDatas().getDataFormatada(rs.getString("inicio")));
            apf.setConclusao(rs.getString("conclusao") == null ? null : new ControlaDatas().getDataFormatada(rs.getString("conclusao")));
            lista.add(apf);
        }
        rs.close();
        stm.close();
    }catch(SQLException e){
        new Notification("Erro tentando select em aperfeiçoamento <br/>", e.getLocalizedMessage(), Notification.Type.ERROR_MESSAGE, true).show(Page.getCurrent());          
    }
    return lista;
}
失败了。在 com.vaadin.event.ListenerMethod.receiveEvent(ListenerMethod.java:528) 在com.vaadin.event.EventRouter.firevent(EventRouter.java:167)上 com.vaadin.server.AbstractClientConnector.fireEvent(AbstractClientConnector.java:969) 在 com.vaadin.ui.AbstractField.fireValueChange(AbstractField.java:1126) 在com.vaadin.ui.AbstractField.setValue(AbstractField.java:542)中 com.vaadin.ui.AbstractSelect.setValue(AbstractSelect.java:702)位于 com.vaadin.ui.AbstractSelect.changeVariables(AbstractSelect.java:521) 位于com.vaadin.ui.Table.changeVariables(Table.java:2880) com.vaadin.server.communication.ServerRpcHandler.changeVariables(ServerRpcHandler.java:396) 在 com.vaadin.server.communication.ServerRpcHandler.handleBurst(ServerRpcHandler.java:221) 在 com.vaadin.server.communication.ServerRpcHandler.handleRpc(ServerRpcHandler.java:111) 在 com.vaadin.server.communication.UidlRequestHandler.SynchronizedHandlerRequest(UidlRequestHandler.java:91) 在 SynchronizedRequestHandler.handleRequest(SynchronizedRequestHandler.java:37) 在 com.vaadin.server.VaadinService.handleRequest(VaadinService.java:1371) 位于com.vaadin.server.VaadinServlet.service(VaadinServlet.java:238) 位于javax.servlet.http.HttpServlet.service(HttpServlet.java:723) org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290) 在 org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) 在 org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233) 在 org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191) 在 org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127) 在 org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103) 在 org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) 在 org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293) 在 org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:861) 在 org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:606) 在 org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489) 在java.lang.Thread.run(Thread.java:724)处,由以下原因引起: 位于的java.lang.NullPointerException br.ind.ibg.unsibg.views.CursosView.valueChange(CursosView.java:304) 位于的sun.reflect.NativeMethodAccessorImpl.invoke0(本机方法) invoke(NativeMethodAccessorImpl.java:57) 在 sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 位于java.lang.reflect.Method.invoke(Method.java:606) com.vaadin.event.ListenerMethod.receiveEvent(ListenerMethod.java:508) ... 还有27个


有什么想法吗?

当您编写setNullSelectionLowed(false)时,并不意味着总是会选择某些项目。 在您的情况下,为了避免NPE:

  • 使用setNullSelectionItemId()设置一些默认值
  • 使用if(event.getProperty().getValue()!=null)检查是否选择了某个项目

哪一行导致NullPointerException?所有行都会导致。当我更改selectshow时会发生NullPointerException,显示错误的堆栈跟踪。“更改选择”是什么意思?我发布了stacktrace!!!下面这行看起来很可疑:br.ind.ibg.unsibg.views.CursosView.valueChange(CursosView.java:304)您能粘贴源代码吗?我确实尝试过,但仍然不起作用<代码>选项卡=新表();tabela.setsizevel();tabela.addContainerProperty(“Aperfeiçoamento”,String.class,null);tabela.addContainerProperty(“Entidade”,String.class,null);tabela.addContainerProperty(“Início”,String.class,null);tabela.addContainerProperty(“conclussão”,String.class,null);tabela.setNullSelectionAllowed(false);tabela.setImmediate(true);tabela.setSelectable(true);tabela.setColumnReorderingAllowed(false);tabela.setNullSelectionItemId(新字符串(“0”);tabela.addValueChangeListener(此)
com.vaadin.event.ListenerMethod$MethodException: Invocation of method valueChange in br.ind.ibg.curriculunsibg.views.CursosView