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

boa tarde galera , sempre acompanhei o GUJ no anonimato , mais hoje criei minha conta e vim pedir uma ajuda a voces.

[code]package controler;

import model.Empres;
import java.util.;
import java.sql.
;

import com.mysql.jdbc.PreparedStatement;

public class DAO {
Connection con;
Statement stm ;
PreparedStatement ps;
Empres emp = new Empres();

public void conectar() {
	try // A captura de exceções SQLException em Java é obrigatória para
		// usarmos JDBC.
	{
		// Este é um dos meios para registrar um driver
		Class.forName("com.mysql.jdbc.Driver");

		// Registrado o driver, vamos estabelecer uma conexão
		 con = DriverManager.getConnection(
				"jdbc:mysql://localhost:4406/mistral","root","senha");
		
		 // Após estabelecermos a conexão com o banco de dados   
		   // Utilizamos o método createStatement de con para criar o Statement   
		   stm = con.createStatement();     

	  
	} catch (SQLException e) {
		// se houve algum erro, uma exceção é gerada para informar o erro
		e.printStackTrace(); // vejamos que erro foi gerado e quem o gerou
	} catch (ClassNotFoundException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}

}//end conectar

public void inserir(){
	conectar();
	

try {
ps.executeUpdate("INSERT INTO cliente ( `nomeemp`, `endereco`, `tipo`, `email`, `tel1`, `tel2`) VALUES ('?','?' ,'?','?','?','?')" );

ps.setString(1, emp.getNomee());
ps.setString(2, emp.getEndereco());
ps.setString(3, emp.getTipo());
ps.setString(4, emp.getEmail());
ps.setString(5, emp.getTel1());
ps.setString(6, emp.getTel2());

} catch (SQLException e) {
	// TODO Auto-generated catch block
	e.printStackTrace();
}  



try {
	con.close();
} catch (SQLException e) {
	// TODO Auto-generated catch block
	e.printStackTrace();
}
try {
	stm.close();
} catch (SQLException e) {
	// TODO Auto-generated catch block
	e.printStackTrace();
}



}

}// end clas
[/code]

[code]package view;

import view.CadastroIn;
import controler.DAO;
import model.Empres;

public class CadastroIn extends javax.swing.JFrame {

public static String a;
public static String b;
public static String c;
public static String d;
public static String e;
public static String f;

/** Creates new form CadastroIn */
public CadastroIn() {
	initComponents();

}

@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {

	jScrollPane1 = new javax.swing.JScrollPane();
	jTextArea1 = new javax.swing.JTextArea();
	jButton1 = new javax.swing.JButton();
	jLabel1 = new javax.swing.JLabel();
	jLabel2 = new javax.swing.JLabel();
	jLabel4 = new javax.swing.JLabel();
	jTextField1 = new javax.swing.JTextField();
	jTextField2 = new javax.swing.JTextField();
	jTextField4 = new javax.swing.JTextField();
	jLabel3 = new javax.swing.JLabel();
	jLabel5 = new javax.swing.JLabel();
	jTextField3 = new javax.swing.JTextField();
	jLabel6 = new javax.swing.JLabel();
	jTextField5 = new javax.swing.JTextField();
	jComboBox1 = new javax.swing.JComboBox();

	jTextArea1.setColumns(20);
	jTextArea1.setRows(5);
	jScrollPane1.setViewportView(jTextArea1);

	setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

	jButton1.setText("cadastrar");
	jButton1.addActionListener(new java.awt.event.ActionListener() {

		public void actionPerformed(java.awt.event.ActionEvent evt) {
			jButton1ActionPerformed(evt);
		}
	});

	jLabel1.setText("nome da empresa");

	jLabel2.setText("endereço");

	jLabel4.setText("tipo de empresa");

	jLabel3.setText("email");

	jLabel5.setText("telefone");

	jLabel6.setText("telefone 2");

	jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] {
			"Matriz", "Filial" }));
	jComboBox1.addActionListener(new java.awt.event.ActionListener() {
		public void actionPerformed(java.awt.event.ActionEvent evt) {
			jComboBox1ActionPerformed(evt);
		}
	});

	javax.swing.GroupLayout layout = new javax.swing.GroupLayout(
			getContentPane());
	getContentPane().setLayout(layout);
	layout.setHorizontalGroup(layout
			.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
			.addGroup(
					layout.createSequentialGroup()
							.addContainerGap()
							.addGroup(
									layout.createParallelGroup(
											javax.swing.GroupLayout.Alignment.LEADING)
											.addGroup(
													layout.createParallelGroup(
															javax.swing.GroupLayout.Alignment.LEADING)
															.addGroup(
																	layout.createParallelGroup(
																			javax.swing.GroupLayout.Alignment.LEADING)
																			.addGroup(
																					layout.createSequentialGroup()
																							.addGroup(
																									layout.createParallelGroup(
																											javax.swing.GroupLayout.Alignment.LEADING)
																											.addComponent(
																													jLabel2)
																											.addComponent(
																													jLabel1)
																											.addComponent(
																													jLabel3,
																													javax.swing.GroupLayout.DEFAULT_SIZE,
																													114,
																													Short.MAX_VALUE))
																							.addGap(47,
																									47,
																									47))
																			.addGroup(
																					layout.createSequentialGroup()
																							.addGap(80,
																									80,
																									80)
																							.addComponent(
																									jButton1))
																			.addComponent(
																					jLabel4))
															.addGroup(
																	layout.createSequentialGroup()
																			.addComponent(
																					jLabel5)
																			.addGap(121,
																					121,
																					121)))
											.addGroup(
													layout.createSequentialGroup()
															.addComponent(
																	jLabel6)
															.addGap(112,
																	112,
																	112)))
							.addGroup(
									layout.createParallelGroup(
											javax.swing.GroupLayout.Alignment.LEADING)
											.addComponent(
													jTextField5,
													javax.swing.GroupLayout.DEFAULT_SIZE,
													177, Short.MAX_VALUE)
											.addComponent(
													jTextField3,
													javax.swing.GroupLayout.DEFAULT_SIZE,
													177, Short.MAX_VALUE)
											.addGroup(
													javax.swing.GroupLayout.Alignment.TRAILING,
													layout.createParallelGroup(
															javax.swing.GroupLayout.Alignment.TRAILING,
															false)
															.addComponent(
																	jTextField2)
															.addComponent(
																	jTextField1,
																	javax.swing.GroupLayout.DEFAULT_SIZE,
																	177,
																	Short.MAX_VALUE)
															.addComponent(
																	jTextField4,
																	javax.swing.GroupLayout.Alignment.LEADING,
																	javax.swing.GroupLayout.DEFAULT_SIZE,
																	177,
																	Short.MAX_VALUE))
											.addComponent(
													jComboBox1,
													javax.swing.GroupLayout.Alignment.TRAILING,
													0, 177, Short.MAX_VALUE))
							.addContainerGap(52,
									javax.swing.GroupLayout.PREFERRED_SIZE)));
	layout.setVerticalGroup(layout
			.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
			.addGroup(
					javax.swing.GroupLayout.Alignment.TRAILING,
					layout.createSequentialGroup()
							.addGap(53, 53, 53)
							.addGroup(
									layout.createParallelGroup(
											javax.swing.GroupLayout.Alignment.BASELINE)
											.addComponent(jLabel1)
											.addComponent(
													jTextField1,
													javax.swing.GroupLayout.PREFERRED_SIZE,
													javax.swing.GroupLayout.DEFAULT_SIZE,
													javax.swing.GroupLayout.PREFERRED_SIZE))
							.addPreferredGap(
									javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
							.addGroup(
									layout.createParallelGroup(
											javax.swing.GroupLayout.Alignment.BASELINE)
											.addComponent(jLabel2)
											.addComponent(
													jTextField2,
													javax.swing.GroupLayout.PREFERRED_SIZE,
													javax.swing.GroupLayout.DEFAULT_SIZE,
													javax.swing.GroupLayout.PREFERRED_SIZE))
							.addPreferredGap(
									javax.swing.LayoutStyle.ComponentPlacement.RELATED)
							.addGroup(
									layout.createParallelGroup(
											javax.swing.GroupLayout.Alignment.BASELINE)
											.addComponent(jLabel4)
											.addComponent(
													jComboBox1,
													javax.swing.GroupLayout.PREFERRED_SIZE,
													javax.swing.GroupLayout.DEFAULT_SIZE,
													javax.swing.GroupLayout.PREFERRED_SIZE))
							.addGap(9, 9, 9)
							.addGroup(
									layout.createParallelGroup(
											javax.swing.GroupLayout.Alignment.BASELINE)
											.addComponent(jLabel3)
											.addComponent(
													jTextField4,
													javax.swing.GroupLayout.PREFERRED_SIZE,
													javax.swing.GroupLayout.DEFAULT_SIZE,
													javax.swing.GroupLayout.PREFERRED_SIZE))
							.addPreferredGap(
									javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
							.addGroup(
									layout.createParallelGroup(
											javax.swing.GroupLayout.Alignment.BASELINE)
											.addComponent(jLabel5)
											.addComponent(
													jTextField3,
													javax.swing.GroupLayout.PREFERRED_SIZE,
													javax.swing.GroupLayout.DEFAULT_SIZE,
													javax.swing.GroupLayout.PREFERRED_SIZE))
							.addPreferredGap(
									javax.swing.LayoutStyle.ComponentPlacement.RELATED)
							.addGroup(
									layout.createParallelGroup(
											javax.swing.GroupLayout.Alignment.BASELINE)
											.addComponent(jLabel6)
											.addComponent(
													jTextField5,
													javax.swing.GroupLayout.PREFERRED_SIZE,
													javax.swing.GroupLayout.DEFAULT_SIZE,
													javax.swing.GroupLayout.PREFERRED_SIZE))
							.addPreferredGap(
									javax.swing.LayoutStyle.ComponentPlacement.RELATED,
									12, Short.MAX_VALUE)
							.addComponent(jButton1).addGap(47, 47, 47)));

	pack();
}



private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
	Empres em = new Empres();
	em.setNomee(jTextField1.getText());
	em.setEndereco(jTextField2.getText())  ;
	
	String texto;   
	  
	switch(jComboBox1.getSelectedIndex())   
	{   
	     case(0):   
	        texto = "Matriz";   
	     break;   
	  
	     case(1):   
	        texto = "Filial";   
	        break;   
	  
	     default:   
	        texto = "";   
	        break;   
	}  

	
	
	em.setTipo(texto) ;
	em.setEmail(jTextField3.getText()) ;
	em.setTel1(jTextField4.getText()) ;
	em.setTel2(jTextField5.getText());
	
	
	System.out.printf("%s\t%s\t%s\t%s\t%s", em.getNomee(), em.getEndereco() ,em.getTipo() ,em.getEmail(), em.getTel1(),em.getTel2());

	DAO dao = new DAO();
	
	dao.inserir();



}

private void jComboBox1ActionPerformed(java.awt.event.ActionEvent evt) {
	// TODO add your handling code here:
}

public static void main(String args[]) {
	java.awt.EventQueue.invokeLater(new Runnable() {
		public void run() {
			new CadastroIn().setVisible(true);
		
		
			
			
			
			
			
		
		
		}
	});
}

// Variables declaration - do not modify
private javax.swing.JButton jButton1;
private javax.swing.JComboBox jComboBox1;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JLabel jLabel5;
private javax.swing.JLabel jLabel6;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JTextArea jTextArea1;
private javax.swing.JTextField jTextField1;
private javax.swing.JTextField jTextField2;
private javax.swing.JTextField jTextField3;
private javax.swing.JTextField jTextField4;
private javax.swing.JTextField jTextField5;
// End of variables declaration

}
[/code]

erro

Matriz Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException at controler.DAO.inserir(DAO.java:48) at view.CadastroIn.jButton1ActionPerformed(CadastroIn.java:285) at view.CadastroIn.access$0(CadastroIn.java:251) at view.CadastroIn$1.actionPerformed(CadastroIn.java:56) 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$000(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) Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException at controler.DAO.inserir(DAO.java:48) at view.CadastroIn.jButton1ActionPerformed(CadastroIn.java:285) at view.CadastroIn.access$0(CadastroIn.java:251) at view.CadastroIn$1.actionPerformed(CadastroIn.java:56) 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$000(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) Matriz Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException at controler.DAO.inserir(DAO.java:48) at view.CadastroIn.jButton1ActionPerformed(CadastroIn.java:285) at view.CadastroIn.access$0(CadastroIn.java:251) at view.CadastroIn$1.actionPerformed(CadastroIn.java:56) 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$000(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) Matriz

e um sistema de cadastro simples , pelo q ja procurei o erro quer dizer q nao inicializei uma variavel , mais nao sei oq inicializar mais =( se puderem ajudar ficaria grato :smiley:

na linha 48 do seu dao vc está chamando o ps.executeUpdate(…) direto sem inicializar o PreparedStatement

ajusta o teu metodo inserir()

    public void inserir() {
        conectar();
        try {
            ps.executeUpdate("INSERT INTO cliente ( `nomeemp`, `endereco`, `tipo`, `email`, `tel1`, `tel2`) VALUES ('?','?' ,'?','?','?','?')");
            
            ps.setString(1, emp.getNomee());
            ps.setString(2, emp.getEndereco());
            ps.setString(3, emp.getTipo());
            ps.setString(4, emp.getEmail());
            ps.setString(5, emp.getTel1());
            ps.setString(6, emp.getTel2());
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        try {
            con.close();
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        try {
            stm.close();
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

mais ou menos assim

    public void inserir() throws Exception {
        try {
            conectar(); // inicializa o con
            
            // primeiro, inicializa (prepara) o comando
            ps = con.prepareStatement("INSERT INTO cliente ( `nomeemp`, `endereco`, `tipo`, `email`, `tel1`, `tel2`) VALUES ('?','?' ,'?','?','?','?')");
            
            // seta os params
            ps.setString(1, emp.getNome());
            ps.setString(2, emp.getEndereco());
            ps.setString(3, emp.getTipo());
            ps.setString(4, emp.getEmail());
            ps.setString(5, emp.getTel1());
            ps.setString(6, emp.getTel2());
            // manda executar
            ps.executeUpdate();
        } finally {
            con.close();
        }
    }

feitow!

já tentou limpar e contruir o projeto?

Acho que você poderia fazer o seguinte na classe DAO.java

Substitua

ps.executeUpdate("INSERT INTO cliente ( `nomeemp`, `endereco`, `tipo`, `email`, `tel1`, `tel2`) VALUES ('?','?' ,'?','?','?','?')" );

por isso

ps = conn.prepareStatement("INSERT INTO cliente ( `nomeemp`, `endereco`, `tipo`, `email`, `tel1`, `tel2`) VALUES ('?','?' ,'?','?','?','?')");

        ps.setString(1, emp.getNomee());  
        ps.setString(2, emp.getEndereco());  
        ps.setString(3, emp.getTipo());  
        ps.setString(4, emp.getEmail());  
        ps.setString(5, emp.getTel1());  
        ps.setString(6, emp.getTel2());

        ps.executeUpdate();

Boa sorte

vlw galera ajudou muitoo!! , agora sem querer pedir de mais alguem tem alguma ideia de como posso passar os dados da tabela pra algum componente do java , para poder verificar os dados ?