Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException

0 respostas
helder.emiliano
Bom dia pessoal, não queria mais criar tópicos, depois que os códigos do meu projeto foram aumentando e acaba se tornando cansativo ler o código , mas depois de 24 horas tentando, desisto!!! to conseguindo cadastrar, pesquisar, recuperar, mas na hora de remover um cadastro, vem o bendito erro... [color=red]Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException at Interfaces.frmCadastroMecanico.ExcluirMecanico(frmCadastroMecanico.java:235) at Interfaces.frmCadastroMecanico.jbExcluirClienteActionPerformed(frmCadastroMecanico.java:224) at Interfaces.frmCadastroMecanico.access$100(frmCadastroMecanico.java:25) at Interfaces.frmCadastroMecanico$2.actionPerformed(frmCadastroMecanico.java:101) at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995) at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318) at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387) at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242) at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236) at java.awt.Component.processMouseEvent(Component.java:6263) at javax.swing.JComponent.processMouseEvent(JComponent.java:3267) at java.awt.Component.processEvent(Component.java:6028) at java.awt.Container.processEvent(Container.java:2041) at java.awt.Component.dispatchEventImpl(Component.java:4630) at java.awt.Container.dispatchEventImpl(Container.java:2099) at java.awt.Component.dispatchEvent(Component.java:4460) at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4574) at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4238) at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4168) at java.awt.Container.dispatchEventImpl(Container.java:2085) at java.awt.Window.dispatchEventImpl(Window.java:2478) at java.awt.Component.dispatchEvent(Component.java:4460) at java.awt.EventQueue.dispatchEvent(EventQueue.java:599) at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269) at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184) at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161) at java.awt.EventDispatchThread.run(EventDispatchThread.java:122) [/color] O .frmCadastroMecanico.jbExcluirClienteActionPerformed(frmCadastroMecanico.java:224) aponta para a linha 14 do seguinte código... dao.remove(pm.ListaMecanico.get(pm.jtTabela.getSelectedRow()));
private void jbExcluirClienteActionPerformed(java.awt.event.ActionEvent evt) {                                                 
        try {
            ExcluirMecanico(); // TODO add your handling code here:
        } catch (SQLException ex) {
            JOptionPane.showMessageDialog(null, "Erro no botão excluir"+ex);
        }
    }                                                
    public void ExcluirMecanico() throws SQLException {
        PesquisaMecanico pm = new PesquisaMecanico();
        int resp = JOptionPane.showConfirmDialog(this, "Deseja realmente excluir este Mecânico?", "Confirmação", JOptionPane.YES_NO_OPTION);
        if (resp == JOptionPane.YES_NO_OPTION) {
            Mecanico dao = new Mecanico();
            
            dao.remove(pm.ListaMecanico.get(pm.jtTabela.getSelectedRow()));
            pm.mostraPesquisa(pm.ListaMecanico);

        }
    }
O código do form pesquisa mecanico(o qual recupera os dados para este formulario é o seguinte:
public class PesquisaMecanico extends javax.swing.JFrame {

    DefaultTableModel tmMecanico = new DefaultTableModel(null, new String[]{"Código", "Nome", "Telefone", "CPF"});
   public List<BeanMecanico> ListaMecanico;
    ListSelectionModel lsmMecanico;

    /** Creates new form PesquisaMecanico */
    public PesquisaMecanico() {
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    
    public void mostraPesquisa(List<BeanMecanico> listaMecanico) {
       if (tmMecanico == null){
           JOptionPane.showMessageDialog(this, "lista vazia");
       }else{
        while(tmMecanico.getRowCount() > 0){
            tmMecanico.removeRow(0);
        }
        if (listaMecanico.size() < 0) {
           JOptionPane.showMessageDialog(null, "Nenhum mecânico no cadastro");
       } else {
        
            String[] linha = new String[]{null, null, null, null};
            for (int i = 0; i < listaMecanico.size(); i++) {
                tmMecanico.addRow(linha);
                tmMecanico.setValueAt(listaMecanico.get(i).getCodMecanico(), i, 0);
                tmMecanico.setValueAt(listaMecanico.get(i).getNomeMecanico(), i, 1);
                tmMecanico.setValueAt(listaMecanico.get(i).getFoneMecanico(), i, 2);
                tmMecanico.setValueAt(listaMecanico.get(i).getCPFMecanico(), i, 3);
            
            }
        }
}
    }
    public void jtTabelaLinhasSelecionadas(JTable tabela){
 frmCadastroMecanico fm = new frmCadastroMecanico();
        if(jtTabela.getSelectedRow() != -1){
fm.jtCodMecanico.setText(ListaMecanico.get(tabela.getSelectedRow()).getCodMecanico());
fm.jtNomeMecanico.setText(ListaMecanico.get(tabela.getSelectedRow()).getNomeMecanico());
fm.jfFoneMecanico.setText(ListaMecanico.get(tabela.getSelectedRow()).getFoneMecanico());
fm.jfCPFMecanico.setText(ListaMecanico.get(tabela.getSelectedRow()).getCPFMecanico());
fm.setVisible(true);
this.setVisible(false);
}else{
            fm.jtCodMecanico.setText("");
            fm.jtNomeMecanico.setText("");
            fm.jfFoneMecanico.setText("");
            fm.jfCPFMecanico.setText("");

}
}
}
Alguém pode me ajudar de alguma maneira? Obrigado...
Criado 23 de junho de 2010
Respostas 0
Participantes 1