2014-01-09 2 views
0

У меня проблема с таблицей vaadin. Когда я меняю строку отображаемых значений, возвращает NullPointerException, и я не знаю почему. В таблице vaadin chapter5 Table существует метод setNullSelectionAllowed (false), когда эта проблема возникает, но все же не работает для меня.NullPointerException в таблице vaadin?

// 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$MethodException: Invocation of method valueChange in br.ind.ibg.curriculunsibg.views.CursosView 

не удалось. на com.vaadin.event.ListenerMethod.receiveEvent (ListenerMethod.java:528) в com.vaadin.event.EventRouter.fireEvent (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.synchronizedHandleRequest (UidlRequestHandler.java:91) на com.vaadin.server.SynchronizedRequestHandler.handleRequest (SynchronizedRequestHandler.java:37) на com.vaadin.server.VaadinService.handleRequest (VaadinService.java:1371) на com.vaadin.server.VaadinServlet.service (VaadinServlet.java:238) at 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) at org.apache.tomcat.util.net.JIoEndpoint $ Worker.run (JIoEndpoint.java:489) at java.lang.Thread.run (Thread.java:724) Вызванный: java.lang.NullPointerException на br.ind.ibg.curriculunsibg.views.CursosView.valueChange (CursosView.java:304) на sun.reflect.NativeMethodAccessorImpl.invoke0 (Родной метод) на sun.reflect.NativeM ethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.Java: 43) в java.lang.reflect.Method.invoke (Method.java:606) в com.vaadin.event.ListenerMethod.receiveEvent (ListenerMethod.java:508) ... 27 более

Любая идея?

+0

какая строка вызывает NullPointerException? – wxyz

+0

все причины строк. Исключение NullPointerException происходит, когда я меняю выбор. – FernandoPaiva

+2

покажите нам stacktrace ошибки. Что вы имеете в виду? – wxyz

ответ

1

Когда вы пишете setNullSelectionAllowed (false), это не означает, что всегда будет выбран какой-то элемент. В случае вас, чтобы избежать NPE:

  • использовать setNullSelectionItemId(), чтобы установить значение, некоторые настройки по умолчанию
  • проверить, если какой-то предмет выбирается, если (event.getProperty() ПолучитьЗначение() = нуль.!)
+0

Я попытался сделать это, но все равно не работает. \t \t tabela = new Table(); \t \t tabela.setSizeFull(); \t \t \t \t tabela.addContainerProperty("Aperfeiçoamento", String.class, null); \t \t tabela.addContainerProperty("Entidade", String.class, null); \t \t tabela.addContainerProperty("Início", String.class, null); \t \t tabela.addContainerProperty("Conclusão", String.class, null); \t \t \t tabela.setNullSelectionAllowed(false); \t \t tabela.setImmediate(true); \t \t tabela.setSelectable(true); \t \t tabela.setColumnReorderingAllowed(false); \t \t tabela.setNullSelectionItemId(new String("0")); \t \t tabela.addValueChangeListener(this); FernandoPaiva

Смежные вопросы