Não consigo salvar dados da minha aplicação no banco de dados do POSTGRES

Exception in thread “AWT-EventQueue-0” java.lang.NullPointerException
at br.com.integrator.cap12.agenda.AgendaEmSwing.salvar(AgendaEmSwing.java:669)
at br.com.integrator.cap12.agenda.AgendaEmSwing.access$3(AgendaEmSwing.java:662)
at br.com.integrator.cap12.agenda.AgendaEmSwing$1.actionPerformed(AgendaEmSwing.java:134)
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.AWTEventMulticaster.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$000(Unknown Source)
at java.awt.EventQueue$1.run(Unknown Source)
at java.awt.EventQueue$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue$2.run(Unknown Source)
at java.awt.EventQueue$2.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$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)




package br.com.integrator.cap12.agenda;

import java.awt.event.KeyEvent;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.Event;
import java.awt.BorderLayout;
import javax.swing.SwingConstants;
import javax.swing.SwingUtilities;
import javax.swing.KeyStroke;
import java.awt.Point;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JMenuItem;
import javax.swing.JMenuBar;
import javax.swing.JMenu;
import javax.swing.JFrame;
import javax.swing.JDialog;
import javax.swing.JToolBar;
import javax.swing.JButton;
import javax.swing.ImageIcon;
import javax.swing.JTabbedPane;
import java.awt.GridBagLayout;
import javax.swing.JScrollPane;
import java.awt.Rectangle;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import javax.swing.JTable;
import javax.swing.JTextField;

import java.awt.Dimension;

public class AgendaEmSwing {

	private JFrame jFrame = null; // @jve:decl-index=0:visual-constraint="10,10"
	private JPanel jContentPane = null;
	private JMenuBar jJMenuBar = null;
	private JMenu fileMenu = null;
	private JMenu helpMenu = null;
	private JMenuItem exitMenuItem = null;
	private JMenuItem aboutMenuItem = null;
	private JMenuItem saveMenuItem = null;
	private JDialog aboutDialog = null;
	private JPanel aboutContentPane = null;
	private JLabel aboutVersionLabel = null;
	private JMenuItem newMenuItem = null;
	private JToolBar jToolBar = null;
	private JButton btSalvar = null;
	private JButton btNovo = null;
	private JButton btExcluir = null;
	private JTabbedPane jTabbedPane = null;
	private JPanel panelAgenda = null;
	private JPanel panelDados = null;
	private JScrollPane jScrollPane = null;
	private JTable jTable = null;
	private Tabela tabela;
	private JLabel jLabel = null;
	private JLabel INome = null;
	private JLabel IEndereco = null;
	private JLabel IBairro = null;
	private JLabel ICidade = null;
	private JLabel IEstado = null;
	private JLabel ICep = null;
	private JLabel ITelefone = null;
	private JTextField tfNome = null;
	private JTextField tfEndereco = null;
	private JTextField tfBairro = null;
	private JTextField tfCidade = null;
	private JTextField tfEstado = null;
	private JTextField tfCep = null;
	private JTextField tfTelefone = null;
	private Conexao conexao; // @jve:decl-index=0:
	private java.sql.ResultSet rs;
	private boolean novo = false;

	public AgendaEmSwing() {
		// TODO Auto-generated constructor stub
	}

	/**
	 * This method initializes newMenuItem
	 * 
	 * @return javax.swing.JMenuItem
	 */
	private JMenuItem getNewMenuItem() {
		if (newMenuItem == null) {
			newMenuItem = new JMenuItem();
			newMenuItem.setText("Novo");
			newMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N,
					Event.CTRL_MASK, true));
		}
		return newMenuItem;
	}

	/**
	 * This method initializes jToolBar
	 * 
	 * @return javax.swing.JToolBar
	 */
	private JToolBar getJToolBar() {
		if (jToolBar == null) {
			jToolBar = new JToolBar();
			jToolBar.add(getBtSalvar());
			jToolBar.addSeparator();
			jToolBar.add(getBtNovo());
			jToolBar.addSeparator();
			jToolBar.add(getBtExcluir());
		}
		return jToolBar;
	}

	/**
	 * This method initializes btSalvar
	 * 
	 * @return javax.swing.JButton
	 */
	private JButton getBtSalvar() {
		if (btSalvar == null) {
			btSalvar = new JButton();
			btSalvar.setToolTipText("Salvar");
			btSalvar.setIcon(new ImageIcon("C:/eclipse/GIF/gravar.gif"));

			btSalvar.setToolTipText("Salvar");
			btSalvar.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					try {
						if (novo == true)
							salvar();
						else
							salvar(rs);
					} catch (SQLException sqlex) {
					}
				}
			});
		}
		return btSalvar;
	}

	/**
	 * This method initializes btNovo
	 * 
	 * @return javax.swing.JButton
	 */
	private JButton getBtNovo() {
		if (btNovo == null) {
			btNovo = new JButton();
			btNovo.setIcon(new ImageIcon("C:/eclipse/GIF/ico_create.gif"));
			btNovo.setToolTipText("Novo");

			btNovo.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					novo();
				}
			});
		}
		return btNovo;
	}

	/**
	 * This method initializes btExcluir
	 * 
	 * @return javax.swing.JButton
	 */
	private JButton getBtExcluir() {
		if (btExcluir == null) {
			btExcluir = new JButton();
			btExcluir.setIcon(new ImageIcon("C:/eclipse/GIF/logout.gif"));
			btExcluir.setToolTipText("Excluir");

			btExcluir.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					try {
						excluir(rs);
					} catch (SQLException sqlex) {
					}
				}
			});
		}
		return btExcluir;
	}

	/**
	 * This method initializes jTabbedPane
	 * 
	 * @return javax.swing.JTabbedPane
	 */
	private JTabbedPane getJTabbedPane() {
		if (jTabbedPane == null) {
			jTabbedPane = new JTabbedPane();
			jTabbedPane.addTab("Agenda", null, getPanelAgenda(), null);
			jTabbedPane.addTab("Dados", null, getPanelDados(), null);
		}
		return jTabbedPane;
	}

	/**
	 * This method initializes panelAgenda
	 * 
	 * @return javax.swing.JPanel
	 */
	private JPanel getPanelAgenda() {
		if (panelAgenda == null) {
			panelAgenda = new JPanel();
			panelAgenda.setLayout(new BorderLayout());
			panelAgenda.add(getJScrollPane(), BorderLayout.CENTER);
		}
		return panelAgenda;
	}

	/**
	 * This method initializes panelDados
	 * 
	 * @return javax.swing.JPanel
	 */
	private JPanel getPanelDados() {
		if (panelDados == null) {
			ITelefone = new JLabel();
			ITelefone.setBounds(new Rectangle(162, 33, 54, 16));
			ITelefone.setText("Telefone:");
			ICep = new JLabel();
			ICep.setBounds(new Rectangle(8, 76, 29, 16));
			ICep.setText("Cep:");
			IEstado = new JLabel();
			IEstado.setBounds(new Rectangle(151, 76, 49, 16));
			IEstado.setText("Estado:");
			ICidade = new JLabel();
			ICidade.setBounds(new Rectangle(3, 55, 48, 16));
			ICidade.setText("Cidade:");
			IBairro = new JLabel();
			IBairro.setBounds(new Rectangle(120, 55, 38, 16));
			IBairro.setText("Bairro:");
			IEndereco = new JLabel();
			IEndereco.setBounds(new Rectangle(1, 34, 60, 16));
			IEndereco.setText("Endereço:");
			INome = new JLabel();
			INome.setBounds(new Rectangle(5, 5, 38, 16));
			INome.setText("Nome:");
			panelDados = new JPanel();
			panelDados.setLayout(null);
			panelDados.add(INome, null);
			panelDados.add(IEndereco, null);
			panelDados.add(IBairro, null);
			panelDados.add(ICidade, null);
			panelDados.add(IEstado, null);
			panelDados.add(ICep, null);
			panelDados.add(ITelefone, null);
			panelDados.add(getTfNome(), null);
			panelDados.add(getTfEndereco(), null);
			panelDados.add(getTfBairro(), null);
			panelDados.add(getTfCidade(), null);
			panelDados.add(getTfEstado(), null);
			panelDados.add(getTfCep(), null);
			panelDados.add(getTfTelefone(), null);
		}
		return panelDados;
	}

	/**
	 * This method initializes jScrollPane
	 * 
	 * @return javax.swing.JScrollPane
	 */
	private JScrollPane getJScrollPane() {
		if (jScrollPane == null) {
			jScrollPane = new JScrollPane();
			jScrollPane.setViewportView(getJTable());
		}
		return jScrollPane;
	}

	/**
	 * This method initializes jTable
	 * 
	 * @return javax.swing.JTable
	 */
	private JTable getJTable() {
		String driver = "org.postgresql.Driver";
		String url = "jdbc:postgresql://localhost:5432/Agenda";
		String user = "postgres";
		String password = "brasil";
		String query = "SELECT nome,telefone FROM agenda.registros";

		try {
			tabela = new Tabela(driver, url, user, password, query);
			conexao = new Conexao();
			conexao.setConnection(url, user, password, driver);
		} catch (ClassNotFoundException classNotFound) {
			JOptionPane.showMessageDialog(null, "Driver não Encontrado",
					"Erro encontrado1", JOptionPane.ERROR_MESSAGE);

		} catch (SQLException sqlex) {
			JOptionPane.showMessageDialog(null, sqlex + " Erro na SQL",
					"Erro encontrado2", JOptionPane.ERROR_MESSAGE);

		}
		if (jTable == null) {
			jTable = new JTable(tabela);

			jTable.addMouseListener(new java.awt.event.MouseAdapter() {
				public void mouseClicked(java.awt.event.MouseEvent e) {
					String SQL = "SELECT * FROM registros WHERE registro";
					SQL += tabela.getValueAt(jTable.getSelectedRow(), 0);
					rs = conexao.setExeQuery(SQL);
					btExcluir.setEnabled(true);
					if (e.getClickCount() == 2) {
						jTabbedPane.setSelectedIndex(1);
						try {

							tfNome.setText(rs.getString(2));
							tfEndereco.setText(rs.getString(3));
							tfBairro.setText(rs.getString(4));
							tfCidade.setText(rs.getString(5));
							tfEstado.setText(rs.getString(6));
							tfCep.setText(rs.getString(7));
							tfTelefone.setText(rs.getString(8));
						} catch (SQLException ex) {
						}
					}

				}
			});
		}
		return jTable;
	}

	/**
	 * This method initializes jLabel
	 * 
	 * @return javax.swing.JLabel
	 */
	private JLabel getJLabel() {
		if (jLabel == null) {
			jLabel = new JLabel();
			jLabel.setText("JLabel");
		}
		return jLabel;
	}

	/**
	 * This method initializes tfNome
	 * 
	 * @return javax.swing.JTextField
	 */
	private JTextField getTfNome() {
		if (tfNome == null) {
			tfNome = new JTextField();
			tfNome.setBounds(new Rectangle(42, 5, 230, 20));
		}
		return tfNome;
	}

	/**
	 * This method initializes tfEndereco
	 * 
	 * @return javax.swing.JTextField
	 */
	private JTextField getTfEndereco() {
		if (tfEndereco == null) {
			tfEndereco = new JTextField();
			tfEndereco.setBounds(new Rectangle(61, 32, 101, 20));
		}
		return tfEndereco;
	}

	/**
	 * This method initializes tfBairro
	 * 
	 * @return javax.swing.JTextField
	 */
	private JTextField getTfBairro() {
		if (tfBairro == null) {
			tfBairro = new JTextField();
			tfBairro.setBounds(new Rectangle(218, 33, 60, 20));
		}
		return tfBairro;
	}

	/**
	 * This method initializes tfCidade
	 * 
	 * @return javax.swing.JTextField
	 */
	private JTextField getTfCidade() {
		if (tfCidade == null) {
			tfCidade = new JTextField();
			tfCidade.setBounds(new Rectangle(52, 54, 67, 20));
		}
		return tfCidade;
	}

	/**
	 * This method initializes tfEstado
	 * 
	 * @return javax.swing.JTextField
	 */
	private JTextField getTfEstado() {
		if (tfEstado == null) {
			tfEstado = new JTextField();
			tfEstado.setBounds(new Rectangle(211, 74, 55, 17));
		}
		return tfEstado;
	}

	/**
	 * This method initializes tfCep
	 * 
	 * @return javax.swing.JTextField
	 */
	private JTextField getTfCep() {
		if (tfCep == null) {
			tfCep = new JTextField();
			tfCep.setBounds(new Rectangle(40, 75, 107, 18));
		}
		return tfCep;
	}

	/**
	 * This method initializes tfTelefone
	 * 
	 * @return javax.swing.JTextField
	 */
	private JTextField getTfTelefone() {
		if (tfTelefone == null) {
			tfTelefone = new JTextField();
			tfTelefone.setBounds(new Rectangle(162, 55, 113, 18));
		}
		return tfTelefone;
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		SwingUtilities.invokeLater(new Runnable() {
			public void run() {
				AgendaEmSwing application = new AgendaEmSwing();
				application.getJFrame().setVisible(true);
			}
		});
	}

	/**
	 * This method initializes jFrame
	 * 
	 * @return javax.swing.JFrame
	 */
	private JFrame getJFrame() {
		if (jFrame == null) {
			jFrame = new JFrame();
			jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
			jFrame.setJMenuBar(getJJMenuBar());
			jFrame.setSize(300, 222);
			jFrame.setContentPane(getJContentPane());
			jFrame.setTitle("Application");
		}
		return jFrame;
	}

	/**
	 * This method initializes jContentPane
	 * 
	 * @return javax.swing.JPanel
	 */
	private JPanel getJContentPane() {
		if (jContentPane == null) {
			jContentPane = new JPanel();
			jContentPane.setLayout(new BorderLayout());
			jContentPane.add(getJToolBar(), BorderLayout.NORTH);
			jContentPane.add(getJTabbedPane(), BorderLayout.CENTER);
		}
		return jContentPane;
	}

	/**
	 * This method initializes jJMenuBar
	 * 
	 * @return javax.swing.JMenuBar
	 */
	private JMenuBar getJJMenuBar() {
		if (jJMenuBar == null) {
			jJMenuBar = new JMenuBar();
			jJMenuBar.add(getFileMenu());
			jJMenuBar.add(getHelpMenu());
		}
		return jJMenuBar;
	}

	/**
	 * This method initializes jMenu
	 * 
	 * @return javax.swing.JMenu
	 */
	private JMenu getFileMenu() {
		if (fileMenu == null) {
			fileMenu = new JMenu();
			fileMenu.setText("Arquivo");
			fileMenu.add(getNewMenuItem());
			fileMenu.add(getSaveMenuItem());
			fileMenu.addSeparator();
			fileMenu.addSeparator();
			fileMenu.add(getExitMenuItem());
		}
		return fileMenu;
	}

	/**
	 * This method initializes jMenu
	 * 
	 * @return javax.swing.JMenu
	 */
	private JMenu getHelpMenu() {
		if (helpMenu == null) {
			helpMenu = new JMenu();
			helpMenu.setText("Ajuda");
			helpMenu.add(getAboutMenuItem());
		}
		return helpMenu;
	}

	/**
	 * This method initializes jMenuItem
	 * 
	 * @return javax.swing.JMenuItem
	 */
	private JMenuItem getExitMenuItem() {
		if (exitMenuItem == null) {
			exitMenuItem = new JMenuItem();
			exitMenuItem.setText("Sair");
			exitMenuItem.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
					tabela.finalize();
					conexao.desconectar();
					System.exit(0);
				}
			});
		}
		return exitMenuItem;
	}

	/**
	 * This method initializes jMenuItem
	 * 
	 * @return javax.swing.JMenuItem
	 */
	private JMenuItem getAboutMenuItem() {
		if (aboutMenuItem == null) {
			aboutMenuItem = new JMenuItem();
			aboutMenuItem.setText("Sobre");
			aboutMenuItem.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
					JDialog aboutDialog = getAboutDialog();
					aboutDialog.pack();
					Point loc = getJFrame().getLocation();
					loc.translate(20, 20);
					aboutDialog.setLocation(loc);
					aboutDialog.setVisible(true);
				}
			});
		}
		return aboutMenuItem;
	}

	/**
	 * This method initializes aboutDialog
	 * 
	 * @return javax.swing.JDialog
	 */
	private JDialog getAboutDialog() {
		if (aboutDialog == null) {
			aboutDialog = new JDialog(getJFrame(), true);
			aboutDialog.setTitle("About");
			aboutDialog.setContentPane(getAboutContentPane());
		}
		return aboutDialog;
	}

	/**
	 * This method initializes aboutContentPane
	 * 
	 * @return javax.swing.JPanel
	 */
	private JPanel getAboutContentPane() {
		if (aboutContentPane == null) {
			aboutContentPane = new JPanel();
			aboutContentPane.setLayout(new BorderLayout());
			aboutContentPane.add(getAboutVersionLabel(), BorderLayout.CENTER);
		}
		return aboutContentPane;
	}

	/**
	 * This method initializes aboutVersionLabel
	 * 
	 * @return javax.swing.JLabel
	 */
	private JLabel getAboutVersionLabel() {
		if (aboutVersionLabel == null) {
			aboutVersionLabel = new JLabel();
			aboutVersionLabel.setText("Version 1.0");
			aboutVersionLabel.setHorizontalAlignment(SwingConstants.CENTER);
		}
		return aboutVersionLabel;
	}

	/**
	 * This method initializes jMenuItem
	 * 
	 * @return javax.swing.JMenuItem
	 */
	private JMenuItem getSaveMenuItem() {
		if (saveMenuItem == null) {
			saveMenuItem = new JMenuItem();
			saveMenuItem.setText("Salvar");
			saveMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S,
					Event.CTRL_MASK, true));
		}
		return saveMenuItem;
	}

	private void excluir(ResultSet rs) throws SQLException {
		int opcao = JOptionPane.showConfirmDialog(null,
				"Tem certeza que você deseja excluir esse cadastro? ",
				"Exclusão Cadastro", JOptionPane.YES_NO_OPTION);
		if (opcao == JOptionPane.YES_OPTION) {
			rs.deleteRow();
			tabela.refresh();
			btExcluir.setEnabled(false);
			rs.close();
		}
	}

	private JTextField[] campos() {
		JTextField[] tf = { tfNome, tfEndereco, tfBairro, tfCidade, tfEstado,
				tfCep, tfTelefone };
		return tf;
	}

	// insert into tabela () values ()
	private void salvar() {
		try {
			JTextField[] tf = campos();
			String SQL = "INSERT INTO Agenda.registros"
					+ "VALUES(null,?,?,?,?,?,?,?)";
			PreparedStatement ps = conexao.setInsert(SQL);
			for (int i = 0; i < tf.length; i++) {
				ps.setString(i + 1, tf[i].getText());
			}
			ps.executeUpdate();
			limpar();
			tabela.refresh();
			ps.close();
			jTabbedPane.setSelectedIndex(0);
			novo = false;
		} catch (SQLException ex) {
			ex.printStackTrace();
		}
	}

	private void salvar(ResultSet rs) throws SQLException {
		JTextField[] tf = campos();
		int opcao = JOptionPane.showConfirmDialog(null,
				"Deseja salvar as alterações desse cadastro?",
				"Alteração de Cadastro", JOptionPane.YES_NO_OPTION);
		if (opcao == JOptionPane.YES_OPTION) {
			for (int i = 0; i < tf.length; i++) {
				rs.updateString(i + 2, tf[i].getText());
				rs.updateRow();
				rs.close();
			}

		}
		tabela.refresh();

	}

	private void limpar() {
		JTextField[] tf = campos();
		for (int i = 0; i < tf.length; i++) {
			tf[i].setText("");
		}
	}

	private void novo() {
		novo = true;
		btExcluir.setEnabled(false);
		jTabbedPane.setSelectedIndex(1);
		limpar();
	}

}

Oi!

Estas duas linhas dizem tudo o que você precisa saber…

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at br.com.integrator.cap12.agenda.AgendaEmSwing.salvar(AgendaEmSwing.java:669) 

Para exemplicar o erro, imagine algo assim:

String s = null;
s.trim();

Vai dar NullPointerException, pois, você possui uma referência, um Objeto, nulo e tenta acessar um determinado método, executar uma ação.
Veja a linha 669 da sua classe AgendaEmSwing, método salvar.

99% de chances de o seu erro estar aqui:

 private void salvar(ResultSet rs) throws SQLException {  
        JTextField[] tf = campos();  
        int opcao = JOptionPane.showConfirmDialog(null,  
                "Deseja salvar as alterações desse cadastro?",  
                "Alteração de Cadastro", JOptionPane.YES_NO_OPTION);  
        if (opcao == JOptionPane.YES_OPTION) {  
            for (int i = 0; i < tf.length; i++) {  // Nessa linha! o tf É NULO
                rs.updateString(i + 2, tf[i].getText());  
                rs.updateRow();  
                rs.close();  
            }  
  
        }  
        tabela.refresh();  
  
    }  

Aposto que o método campos(); está retornando nulo, ai você faz algo do tipo:

E já era, exceção. Reveja seu método campos() e/ou lógica.
Abraços.

Tudo bem aonde esta o erro eu descobri, só que não tive solução que de certo você pode me ajudar???

se o erro for mesmo que o metodo campos() retorna null, eh porque vc nao iniciou os objetos q o vetor JTextField[] tf reccebe…

se nao for, aprenda a usar o DEBUG e coloque aqui a linha aonde esta o problema…

private JTextField[] campos() {
JTextField[] tf = { tfNome, tfEndereco, tfBairro, tfCidade, tfEstado,
tfCep, tfTelefone };
return tf;
}

nao esta retornando null, e tf foi inicializado

so que ja tentei e nao consegui resolver o codigo todo esta no inicio, nao da para dar um observada e me dizer !!!

tente deixar seu método campo() assim:

[quote] private JTextField[] getCampos() {
return new JTextField[] { tfNome, tfEndereco, tfBairro, tfCidade, tfEstado,
tfCep, tfTelefone };
} [/quote]

eu n achei aonde vc inicializou as textField… elas eh q devem ser inicializadas

Exception in thread “AWT-EventQueue-0” java.lang.NullPointerException at br.com.integrator.cap12.agenda.AgendaEmSwing.salvar(AgendaEmSwing.java:674)
at br.com.integrator.cap12.agenda.AgendaEmSwing.access$3(AgendaEmSwing.java:667)
at br.com.integrator.cap12.agenda.AgendaEmSwing$1.actionPerformed(AgendaEmSwing.java:133)

Agora esta aparecendo este erro!!!

Alguem pode me dar uma força, pode parecer chato mais necessito de ajuda

vou tentar inicializar a textfild

vc inicia so no momento em q da get

entao faz assim:

private JTextField[] campos() { JTextField[] tf = { getTfNome(), getTfEndereco(), getTfBairro(), getTfCidade(), getTfEstado(),getTfCep(), getTfTelefone() }; return tf; }

Exception in thread “AWT-EventQueue-0” java.lang.NullPointerException
at br.com.integrator.cap12.agenda.AgendaEmSwing.salvar(AgendaEmSwing.java:674)
at br.com.integrator.cap12.agenda.AgendaEmSwing.access$3(AgendaEmSwing.java:667)
at br.com.integrator.cap12.agenda.AgendaEmSwing$1.actionPerformed(AgendaEmSwing.java:133)

Apareceu este erro agora!!!

inicia todas textfield na declaração, la em cima…

se nao funcionar, usa o debug e posta aonde exatamennte da o erro

tente isso:

private JTextField[] getCampos() { 
return new JTextField[] { getTfNome(), getTfEndereco(), getTfBairro(), getTfCidade(), getTfEstado(),getTfCep(), getTfTelefone() };
}

AgendaEmSwing [Java Application]	
	br.com.integrator.cap12.agenda.AgendaEmSwing at localhost:49659	
		Thread [AWT-Shutdown] (Running)	
		Daemon Thread [AWT-Windows] (Running)	
		Thread [DestroyJavaVM] (Running)	
		Thread [AWT-EventQueue-0] (Running)	
	C:\Program Files\Java\jre6\bin\javaw.exe (19/06/2011 11:13:48)	
AgendaEmSwing [Java Application]	
	br.com.integrator.cap12.agenda.AgendaEmSwing at localhost:49663	
		Daemon Thread [AWT-Windows] (Running)	
		Thread [AWT-Shutdown] (Running)	
		Thread [DestroyJavaVM] (Running)	
		Thread [AWT-EventQueue-0] (Running)	
	C:\Program Files\Java\jre6\bin\javaw.exe (19/06/2011 11:16:36)	
AgendaEmSwing [Java Application]	
	br.com.integrator.cap12.agenda.AgendaEmSwing at localhost:49667	
		Thread [AWT-Shutdown] (Running)	
		Daemon Thread [AWT-Windows] (Running)	
		Thread [DestroyJavaVM] (Running)	
		Thread [AWT-EventQueue-0] (Suspended (breakpoint at line 81 in AgendaEmSwing))	
			AgendaEmSwing.<init>() line: 81	
			AgendaEmSwing$5.run() line: 440	
			InvocationEvent.dispatch() line: not available	
			EventQueue.dispatchEventImpl(AWTEvent, Object) line: not available	
			EventQueue.access$000(EventQueue, AWTEvent, Object) line: not available	
			EventQueue$1.run() line: not available	
			EventQueue$1.run() line: not available	
			AccessController.doPrivileged(PrivilegedAction<T>, AccessControlContext) line: not available [native method]	
			AccessControlContext$1.doIntersectionPrivilege(PrivilegedAction<T>, AccessControlContext, AccessControlContext) line: not available	
			EventQueue.dispatchEvent(AWTEvent) line: not available	
			EventDispatchThread.pumpOneEventForFilters(int) line: not available	
			EventDispatchThread.pumpEventsForFilter(int, Conditional, EventFilter) line: not available	
			EventDispatchThread.pumpEventsForHierarchy(int, Conditional, Component) line: not available	
			EventDispatchThread.pumpEvents(int, Conditional) line: not available	
			EventDispatchThread.pumpEvents(Conditional) line: not available	
			EventDispatchThread.run() line: not available	
	C:\Program Files\Java\jre6\bin\javaw.exe (19/06/2011 11:17:22)	

DEBUG

Alguém pode me ajudar com o código!!!

Movido para o fórum de persistência. Por favor, leia com atenção a descrição dos fóruns antes de postar.

Com relação a salvar no meu banco de dados resolvi, so que algora aparece outro erro!!!

Exception in thread “AWT-EventQueue-0” java.lang.NullPointerException
at br.com.integrator.cap12.agenda.AgendaEmSwing.excluir(AgendaEmSwing.java:629)
at br.com.integrator.cap12.agenda.AgendaEmSwing.access$5(AgendaEmSwing.java:624)
at br.com.integrator.cap12.agenda.AgendaEmSwing$3.actionPerformed(AgendaEmSwing.java:176)
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.AWTEventMulticaster.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$000(Unknown Source)
at java.awt.EventQueue$1.run(Unknown Source)
at java.awt.EventQueue$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue$2.run(Unknown Source)
at java.awt.EventQueue$2.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$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)
org.postgresql.util.PSQLException: ERRO: coluna “id” é do tipo integer mas expressão é do tipo character varying
Dica: Você precisará reescrever ou converter a expressão.
Posição: 38
at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2102)
at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1835)
at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:257)
at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:500)
at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:388)
at org.postgresql.jdbc2.AbstractJdbc2Statement.executeUpdate(AbstractJdbc2Statement.java:334)
at br.com.integrator.cap12.agenda.AgendaEmSwing.salvar(AgendaEmSwing.java:656)
at br.com.integrator.cap12.agenda.AgendaEmSwing.access$2(AgendaEmSwing.java:642)
at br.com.integrator.cap12.agenda.AgendaEmSwing$1.actionPerformed(AgendaEmSwing.java:131)
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.AWTEventMulticaster.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$000(Unknown Source)
at java.awt.EventQueue$1.run(Unknown Source)
at java.awt.EventQueue$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue$2.run(Unknown Source)
at java.awt.EventQueue$2.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$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)


package br.com.integrator.cap12.agenda;

import java.awt.event.KeyEvent;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.Event;
import java.awt.BorderLayout;
import javax.swing.SwingConstants;
import javax.swing.SwingUtilities;
import javax.swing.KeyStroke;
import java.awt.Point;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JMenuItem;
import javax.swing.JMenuBar;
import javax.swing.JMenu;
import javax.swing.JFrame;
import javax.swing.JDialog;
import javax.swing.JToolBar;
import javax.swing.JButton;
import javax.swing.ImageIcon;
import javax.swing.JTabbedPane;
import java.awt.GridBagLayout;
import javax.swing.JScrollPane;
import java.awt.Rectangle;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import javax.swing.JTable;
import javax.swing.JTextField;

import java.awt.Dimension;

public class AgendaEmSwing {

	private JFrame jFrame = null; // @jve:decl-index=0:visual-constraint="10,10"
	private JPanel jContentPane = null;
	private JMenuBar jJMenuBar = null;
	private JMenu fileMenu = null;
	private JMenu helpMenu = null;
	private JMenuItem exitMenuItem = null;
	private JMenuItem aboutMenuItem = null;
	private JMenuItem saveMenuItem = null;
	private JDialog aboutDialog = null;
	private JPanel aboutContentPane = null;
	private JLabel aboutVersionLabel = null;
	private JMenuItem newMenuItem = null;
	private JToolBar jToolBar = null;
	private JButton btSalvar = null;
	private JButton btNovo = null;
	private JButton btExcluir = null;
	private JTabbedPane jTabbedPane = null;
	private JPanel panelAgenda = null;
	private JPanel panelDados = null;
	private JScrollPane jScrollPane = null;
	private JTable jTable = null;
	private Tabela tabela;
	private JLabel jLabel = null;
	private JLabel INome = null;
	private JLabel IEndereco = null;
	private JLabel IBairro = null;
	private JLabel ICidade = null;
	private JLabel IEstado = null;
	private JLabel ICep = null;
	private JLabel ITelefone = null;
	private JTextField tfNome = null;
	private JTextField tfEndereco = null;
	private JTextField tfBairro = null;
	private JTextField tfCidade = null;
	private JTextField tfEstado = null;
	private JTextField tfCep = null;
	private JTextField tfTelefone = null;
	private Conexao conexao; // @jve:decl-index=0:
	private java.sql.ResultSet rs;
	private boolean novo = false;

	public AgendaEmSwing() {
		// TODO Auto-generated constructor stub
	}

	/**
	 * This method initializes newMenuItem
	 * 
	 * @return javax.swing.JMenuItem
	 */
	private JMenuItem getNewMenuItem() {
		if (newMenuItem == null) {
			newMenuItem = new JMenuItem();
			newMenuItem.setText("Novo");
			newMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N,
					Event.CTRL_MASK, true));
		}
		return newMenuItem;
	}

	/**
	 * This method initializes jToolBar
	 * 
	 * @return javax.swing.JToolBar
	 */
	private JToolBar getJToolBar() {
		if (jToolBar == null) {
			jToolBar = new JToolBar();
			jToolBar.add(getBtSalvar());
			jToolBar.addSeparator();
			jToolBar.add(getBtNovo());
			jToolBar.addSeparator();
			jToolBar.add(getBtExcluir());
		}
		return jToolBar;
	}

	/**
	 * This method initializes btSalvar
	 * 
	 * @return javax.swing.JButton
	 */
	private JButton getBtSalvar() {
		if (btSalvar == null) {
			btSalvar = new JButton();
			btSalvar.setToolTipText("Salvar");
			btSalvar.setIcon(new ImageIcon("C:/eclipse/GIF/gravar.gif"));

			btSalvar.setToolTipText("Salvar");
			btSalvar.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					try {
						if (novo == false)
							salvar(rs);
						else
							getsalvar(rs);
					} catch (SQLException sqlex) {
					}
				}
			});
		}
		return btSalvar;
	}

	/**
	 * This method initializes btNovo
	 * 
	 * @return javax.swing.JButton
	 */
	private JButton getBtNovo() {
		if (btNovo == null) {
			btNovo = new JButton();
			btNovo.setIcon(new ImageIcon("C:/eclipse/GIF/ico_create.gif"));
			btNovo.setToolTipText("Novo");

			btNovo.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					getnovo();
				}
			});
		}
		return btNovo;
	}

	/**
	 * This method initializes btExcluir
	 * 
	 * @return javax.swing.JButton
	 */
	private JButton getBtExcluir() {
		if (btExcluir == null) {
			btExcluir = new JButton();
			btExcluir.setIcon(new ImageIcon("C:/eclipse/GIF/logout.gif"));
			btExcluir.setToolTipText("Excluir");

			btExcluir.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					try {
						excluir(rs);
					} catch (SQLException sqlex) {
					}
				}
			});
		}
		return btExcluir;
	}

	/**
	 * This method initializes jTabbedPane
	 * 
	 * @return javax.swing.JTabbedPane
	 */
	private JTabbedPane getJTabbedPane() {
		if (jTabbedPane == null) {
			jTabbedPane = new JTabbedPane();
			jTabbedPane.addTab("Agenda", null, getPanelAgenda(), null);
			jTabbedPane.addTab("Dados", null, getPanelDados(), null);
		}
		return jTabbedPane;
	}

	/**
	 * This method initializes panelAgenda
	 * 
	 * @return javax.swing.JPanel
	 */
	private JPanel getPanelAgenda() {
		if (panelAgenda == null) {
			panelAgenda = new JPanel();
			panelAgenda.setLayout(new BorderLayout());
			panelAgenda.add(getJScrollPane(), BorderLayout.CENTER);
		}
		return panelAgenda;
	}

	/**
	 * This method initializes panelDados
	 * 
	 * @return javax.swing.JPanel
	 */
	private JPanel getPanelDados() {
		if (panelDados == null) {
			ITelefone = new JLabel();
			ITelefone.setBounds(new Rectangle(162, 33, 54, 16));
			ITelefone.setText("Telefone:");
			ICep = new JLabel();
			ICep.setBounds(new Rectangle(8, 76, 29, 16));
			ICep.setText("Cep:");
			IEstado = new JLabel();
			IEstado.setBounds(new Rectangle(151, 76, 49, 16));
			IEstado.setText("Estado:");
			ICidade = new JLabel();
			ICidade.setBounds(new Rectangle(3, 55, 48, 16));
			ICidade.setText("Cidade:");
			IBairro = new JLabel();
			IBairro.setBounds(new Rectangle(120, 55, 38, 16));
			IBairro.setText("Bairro:");
			IEndereco = new JLabel();
			IEndereco.setBounds(new Rectangle(1, 34, 60, 16));
			IEndereco.setText("Endereço:");
			INome = new JLabel();
			INome.setBounds(new Rectangle(5, 5, 38, 16));
			INome.setText("Nome:");
			panelDados = new JPanel();
			panelDados.setLayout(null);
			panelDados.add(INome, null);
			panelDados.add(IEndereco, null);
			panelDados.add(IBairro, null);
			panelDados.add(ICidade, null);
			panelDados.add(IEstado, null);
			panelDados.add(ICep, null);
			panelDados.add(ITelefone, null);
			panelDados.add(getTfNome(), null);
			panelDados.add(getTfEndereco(), null);
			panelDados.add(getTfBairro(), null);
			panelDados.add(getTfCidade(), null);
			panelDados.add(getTfEstado(), null);
			panelDados.add(getTfCep(), null);
			panelDados.add(getTfTelefone(), null);
		}
		return panelDados;
	}

	/**
	 * This method initializes jScrollPane
	 * 
	 * @return javax.swing.JScrollPane
	 */
	private JScrollPane getJScrollPane() {
		if (jScrollPane == null) {
			jScrollPane = new JScrollPane();
			jScrollPane.setViewportView(getJTable());
		}
		return jScrollPane;
	}

	/**
	 * This method initializes jTable
	 * 
	 * @return javax.swing.JTable
	 */
	private JTable getJTable() {
		String driver = "org.postgresql.Driver";
		String url = "jdbc:postgresql://localhost:5432/Agenda";
		String user = "postgres";
		String password = "brasil";
		String query = "SELECT nome,telefone FROM agenda.registros";

		try {
			tabela = new Tabela(driver, url, user, password, query);
			conexao = new Conexao();
			conexao.setConnection(url, user, password, driver);
		} catch (ClassNotFoundException classNotFound) {
			JOptionPane.showMessageDialog(null, "Driver não Encontrado",
					"Erro encontrado1", JOptionPane.ERROR_MESSAGE);

		} catch (SQLException sqlex) {
			JOptionPane.showMessageDialog(null, sqlex + " Erro na SQL",
					"Erro encontrado2", JOptionPane.ERROR_MESSAGE);

		}
		if (jTable == null) {
			jTable = new JTable(tabela);

			jTable.addMouseListener(new java.awt.event.MouseAdapter() {
				public void mouseClicked(java.awt.event.MouseEvent e) {
					String SQL = "SELECT * FROM registros WHERE registro";
					SQL += tabela.getValueAt(jTable.getSelectedRow(), 0);
					rs = conexao.setExeQuery(SQL);
					btExcluir.setEnabled(true);
					if (e.getClickCount() == 2) {
						jTabbedPane.setSelectedIndex(1);
						try {

							tfNome.setText(rs.getString(2));
							tfEndereco.setText(rs.getString(3));
							tfBairro.setText(rs.getString(4));
							tfCidade.setText(rs.getString(5));
							tfEstado.setText(rs.getString(6));
							tfCep.setText(rs.getString(7));
							tfTelefone.setText(rs.getString(8));
						} catch (SQLException ex) {
						}
					}

				}
			});
		}
		return jTable;
	}

	/**
	 * This method initializes jLabel
	 * 
	 * @return javax.swing.JLabel
	 */
	private JLabel getJLabel() {
		if (jLabel == null) {
			jLabel = new JLabel();
			jLabel.setText("JLabel");
		}
		return jLabel;
	}

	/**
	 * This method initializes tfNome
	 * 
	 * @return javax.swing.JTextField
	 */
	private JTextField getTfNome() {
		if (tfNome == null) {
			tfNome = new JTextField();
			tfNome.setBounds(new Rectangle(42, 5, 230, 20));
		}
		return tfNome;
	}

	/**
	 * This method initializes tfEndereco
	 * 
	 * @return javax.swing.JTextField
	 */
	private JTextField getTfEndereco() {
		if (tfEndereco == null) {
			tfEndereco = new JTextField();
			tfEndereco.setBounds(new Rectangle(61, 32, 101, 20));
		}
		return tfEndereco;
	}

	/**
	 * This method initializes tfBairro
	 * 
	 * @return javax.swing.JTextField
	 */
	private JTextField getTfBairro() {
		if (tfBairro == null) {
			tfBairro = new JTextField();
			tfBairro.setBounds(new Rectangle(218, 33, 60, 20));
		}
		return tfBairro;
	}

	/**
	 * This method initializes tfCidade
	 * 
	 * @return javax.swing.JTextField
	 */
	private JTextField getTfCidade() {
		if (tfCidade == null) {
			tfCidade = new JTextField();
			tfCidade.setBounds(new Rectangle(52, 54, 67, 20));
		}
		return tfCidade;
	}

	/**
	 * This method initializes tfEstado
	 * 
	 * @return javax.swing.JTextField
	 */
	private JTextField getTfEstado() {
		if (tfEstado == null) {
			tfEstado = new JTextField();
			tfEstado.setBounds(new Rectangle(211, 74, 55, 17));
		}
		return tfEstado;
	}

	/**
	 * This method initializes tfCep
	 * 
	 * @return javax.swing.JTextField
	 */
	private JTextField getTfCep() {
		if (tfCep == null) {
			tfCep = new JTextField();
			tfCep.setBounds(new Rectangle(40, 75, 107, 18));
		}
		return tfCep;
	}

	/**
	 * This method initializes tfTelefone
	 * 
	 * @return javax.swing.JTextField
	 */
	private JTextField getTfTelefone() {
		if (tfTelefone == null) {
			tfTelefone = new JTextField();
			tfTelefone.setBounds(new Rectangle(162, 55, 113, 18));
		}
		return tfTelefone;
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		SwingUtilities.invokeLater(new Runnable() {
			public void run() {
				AgendaEmSwing application = new AgendaEmSwing();
				application.getJFrame().setVisible(true);
			}
		});
	}

	/**
	 * This method initializes jFrame
	 * 
	 * @return javax.swing.JFrame
	 */
	private JFrame getJFrame() {
		if (jFrame == null) {
			jFrame = new JFrame();
			jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
			jFrame.setJMenuBar(getJJMenuBar());
			jFrame.setSize(300, 222);
			jFrame.setContentPane(getJContentPane());
			jFrame.setTitle("Application");
		}
		return jFrame;
	}

	/**
	 * This method initializes jContentPane
	 * 
	 * @return javax.swing.JPanel
	 */
	private JPanel getJContentPane() {
		if (jContentPane == null) {
			jContentPane = new JPanel();
			jContentPane.setLayout(new BorderLayout());
			jContentPane.add(getJToolBar(), BorderLayout.NORTH);
			jContentPane.add(getJTabbedPane(), BorderLayout.CENTER);
		}
		return jContentPane;
	}

	/**
	 * This method initializes jJMenuBar
	 * 
	 * @return javax.swing.JMenuBar
	 */
	private JMenuBar getJJMenuBar() {
		if (jJMenuBar == null) {
			jJMenuBar = new JMenuBar();
			jJMenuBar.add(getFileMenu());
			jJMenuBar.add(getHelpMenu());
		}
		return jJMenuBar;
	}

	/**
	 * This method initializes jMenu
	 * 
	 * @return javax.swing.JMenu
	 */
	private JMenu getFileMenu() {
		if (fileMenu == null) {
			fileMenu = new JMenu();
			fileMenu.setText("Arquivo");
			fileMenu.add(getNewMenuItem());
			fileMenu.add(getSaveMenuItem());
			fileMenu.addSeparator();
			fileMenu.addSeparator();
			fileMenu.add(getExitMenuItem());
		}
		return fileMenu;
	}

	/**
	 * This method initializes jMenu
	 * 
	 * @return javax.swing.JMenu
	 */
	private JMenu getHelpMenu() {
		if (helpMenu == null) {
			helpMenu = new JMenu();
			helpMenu.setText("Ajuda");
			helpMenu.add(getAboutMenuItem());
		}
		return helpMenu;
	}

	/**
	 * This method initializes jMenuItem
	 * 
	 * @return javax.swing.JMenuItem
	 */
	private JMenuItem getExitMenuItem() {
		if (exitMenuItem == null) {
			exitMenuItem = new JMenuItem();
			exitMenuItem.setText("Sair");
			exitMenuItem.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
					tabela.finalize();
					conexao.desconectar();
					System.exit(0);
				}
			});
		}
		return exitMenuItem;
	}

	/**
	 * This method initializes jMenuItem
	 * 
	 * @return javax.swing.JMenuItem
	 */
	private JMenuItem getAboutMenuItem() {
		if (aboutMenuItem == null) {
			aboutMenuItem = new JMenuItem();
			aboutMenuItem.setText("Sobre");
			aboutMenuItem.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
					JDialog aboutDialog = getAboutDialog();
					aboutDialog.pack();
					Point loc = getJFrame().getLocation();
					loc.translate(20, 20);
					aboutDialog.setLocation(loc);
					aboutDialog.setVisible(true);
				}
			});
		}
		return aboutMenuItem;
	}

	/**
	 * This method initializes aboutDialog
	 * 
	 * @return javax.swing.JDialog
	 */
	private JDialog getAboutDialog() {
		if (aboutDialog == null) {
			aboutDialog = new JDialog(getJFrame(), true);
			aboutDialog.setTitle("About");
			aboutDialog.setContentPane(getAboutContentPane());
		}
		return aboutDialog;
	}

	/**
	 * This method initializes aboutContentPane
	 * 
	 * @return javax.swing.JPanel
	 */
	private JPanel getAboutContentPane() {
		if (aboutContentPane == null) {
			aboutContentPane = new JPanel();
			aboutContentPane.setLayout(new BorderLayout());
			aboutContentPane.add(getAboutVersionLabel(), BorderLayout.CENTER);
		}
		return aboutContentPane;
	}

	/**
	 * This method initializes aboutVersionLabel
	 * 
	 * @return javax.swing.JLabel
	 */
	private JLabel getAboutVersionLabel() {
		if (aboutVersionLabel == null) {
			aboutVersionLabel = new JLabel();
			aboutVersionLabel.setText("Version 1.0");
			aboutVersionLabel.setHorizontalAlignment(SwingConstants.CENTER);
		}
		return aboutVersionLabel;
	}

	/**
	 * This method initializes jMenuItem
	 * 
	 * @return javax.swing.JMenuItem
	 */
	private JMenuItem getSaveMenuItem() {
		if (saveMenuItem == null) {
			saveMenuItem = new JMenuItem();
			saveMenuItem.setText("Salvar");
			saveMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S,
					Event.CTRL_MASK, true));
		}
		return saveMenuItem;
	}

	private void excluir(ResultSet rs) throws SQLException {
		int opcao = JOptionPane.showConfirmDialog(null,
				"Tem certeza que você deseja excluir esse cadastro? ",
				"Exclusão Cadastro", JOptionPane.YES_NO_OPTION);
		if (opcao == JOptionPane.YES_OPTION) {
			rs.deleteRow();
			tabela.refresh();
			btExcluir.setEnabled(false);
			rs.close();
		}
	}

	private JTextField[] getcampos() {
		JTextField[] tf = { tfNome, tfEndereco, tfBairro, tfCidade, tfEstado,
				tfCep, tfTelefone };
		return tf;
	}

	private void salvar(ResultSet rs) throws SQLException {
		try {
			JTextField[] tf = getcampos();
			int opcao = JOptionPane.showConfirmDialog(null,
					"Deseja salvar  cadastro?", "Salvar Cadastro",
					JOptionPane.YES_NO_OPTION);
			if (opcao == JOptionPane.YES_OPTION) {
				String SQL = "INSERT INTO agenda.registros "//(nome,endereco,bairro,cidade,estado,cep,telefone )"
						+ "VALUES (?,?,?,?,?,?,?)";
				PreparedStatement ps = conexao.setInsert(SQL);
				for (int i = 0; i < tf.length; i++) {
					ps.setString(i + 1, tf[i].getText());
				}
				
				ps.executeUpdate();
				getlimpar();
				tabela.refresh();
				ps.close();
				jTabbedPane.setSelectedIndex(0);
				novo = false;
			}
		} catch (SQLException ex) {
			ex.printStackTrace();
		}
	}

	private void getsalvar(ResultSet rs) throws SQLException {
		JTextField[] tf = getcampos();
		int opcao = JOptionPane.showConfirmDialog(null,
				"Deseja salvar as alterações desse cadastro?",
				"Alteração de Cadastro", JOptionPane.YES_NO_OPTION);
		if (opcao == JOptionPane.YES_OPTION) {
			for (int i = 0; i < tf.length; i++) {
				rs.updateString(i + 2, tf[i].getText());
				rs.updateRow();
				rs.close();
			}

		}
		tabela.refresh();

	}

	private void getlimpar() {
		JTextField[] tf = getcampos();
		for (int i = 0; i < tf.length; i++) {
			tf[i].setText("");
		}
	}

	private void getnovo() {
		novo = true;
		btExcluir.setEnabled(false);
		jTabbedPane.setSelectedIndex(1);
		getlimpar();
	}

}

O actionPerformed do btnExcluir não está inicializando a variável rs. Aí ela obviamente estará nula.