Olá, eu meu projeto de cadastro de paciente é pelo formato MVC(Fachada, contorlador, repositorio), e eu ja consegui fazer os botoes de salvar, e pesquisar no BD pelo idPaciente.
minha duvida é quando eu pesquiso pelo idPaciente, e quero alterar algum campo.
meu codigo esta dando erro. seguem abaixo:
BOTAO ALTERAR
[code]btnSalvar.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
try {
Alterar();
} catch (NumberFormatException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (UsuarioNaoEncontradoException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (RepositorioException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}[/code]
METODO ALTERAR
[code]public void Alterar() throws NumberFormatException, UsuarioNaoEncontradoException, RepositorioException, SQLException{
// paciente = fachada.pacienteProcurar(Integer.parseInt(tfIdPaciente.getText()));
paciente = new Paciente(tfNome.getText(), tfApelido.getText(), tfEmail.getText(),tfCelular.getText(),Integer.parseInt(tfIdade.getText()), tfEndereco.getText(), tfTelefone.getText(), tpSenha.getText());
//JOptionPane.showMessageDialog(null, usuario.getNome() + " " + usuario.getAltura());
// paciente.setidPaciente(Integer.parseInt(tfIdPaciente.getText()));
paciente.setNome(tfNome.getText());
paciente.setApelido(tfApelido.getText());
paciente.setEmail(tfEmail.getText());
paciente.setEndereco(tfEndereco.getText());
fachada.pacienteAtualizar(paciente);
JOptionPane.showMessageDialog(null,"Usuário atualizado com sucesso");
}[/code]
FACHADA
public void pacienteAtualizar(Paciente paciente) throws UsuarioNaoEncontradoException, RepositorioException, SQLException {
this.controladorPaciente.atualizar(paciente);
}
CONTROLADOR
[code] public void atualizar(Paciente paciente) throws UsuarioNaoEncontradoException, RepositorioException, SQLException {
CadastroPaciente cadastroPaciente = new CadastroPaciente(this.repositorioPaciente);
// Validações da Classe Cliente
// Validações da Classe Usuario
if (paciente.getNome() == “” ||
paciente.getSenha() == “” ||
paciente.getIdade() == 0 ) {
//throw new DadosInvalidosException(“CPF” + pessoaFis.getCpf() + " ou Nome Inválido!");
} else{
cadastroPaciente.atualizar(paciente);
}[/code]
E o erro é esse :
Conectado com sucesso
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at PacienteView.PacienteAlterar.Alterar(PacienteAlterar.java:355)
at PacienteView.PacienteAlterar$4.actionPerformed(PacienteAlterar.java:255)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$400(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
Seguem 2 imagens anexadas para melhor visualizacao
Quem souber por favor me ajuda.