Boa noite, estou com erro de NullPointerException no código abaixo, e ainda não encontrei o erro
/*
- To change this license header, choose License Headers in Project Properties.
- To change this template file, choose Tools | Templates
- and open the template in the editor.
*/
package Tela_inicial;
import javax.swing.GroupLayout.Alignment;
import javax.swing.GroupLayout;
import javax.swing.LayoutStyle.ComponentPlacement;
import Classes_conexao.Conexao;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.sql.Connection;
import java.sql.PreparedStatement;
//import java.sql.SQLException;
import java.awt.event.ActionEvent;
//import javax.swing.JPanel;
import javax.swing.JLayeredPane;
import javax.swing.JOptionPane;
//import javax.swing.JInternalFrame;
//import javax.swing.JSeparator;
//import java.awt.Panel;
//import java.awt.Canvas;
import javax.swing.JLabel;
import javax.swing.JTextField;
import java.awt.Font;
/**
*
-
@author dougl
*/
public class Cadastro_produtos extends javax.swing.JFrame {/**
/
private static final long serialVersionUID = 1L;
/*- Creates new form NewJFrame
*/
public Cadastro_produtos() {
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.
*/
private void initComponents() {
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); JLabel lblCadastroDeProdutos = new JLabel("Cadastro de produtos"); lblCadastroDeProdutos.setFont(new Font("Tahoma", Font.BOLD, 15)); JLayeredPane layeredPane = new JLayeredPane(); JLayeredPane layeredPane_1 = new JLayeredPane(); layeredPane_2 = new JLayeredPane(); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); layout.setHorizontalGroup( layout.createParallelGroup(Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGap(60) .addGroup(layout.createParallelGroup(Alignment.LEADING) .addComponent(lblCadastroDeProdutos) .addGroup(layout.createParallelGroup(Alignment.LEADING, false) .addComponent(layeredPane, GroupLayout.DEFAULT_SIZE, 374, Short.MAX_VALUE) .addComponent(layeredPane_1, GroupLayout.PREFERRED_SIZE, 422, GroupLayout.PREFERRED_SIZE) .addComponent(layeredPane_2, Alignment.TRAILING, GroupLayout.PREFERRED_SIZE, 300, GroupLayout.PREFERRED_SIZE))) .addGap(137)) ); layout.setVerticalGroup( layout.createParallelGroup(Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addContainerGap() .addComponent(lblCadastroDeProdutos) .addPreferredGap(ComponentPlacement.RELATED) .addComponent(layeredPane_1, GroupLayout.PREFERRED_SIZE, 157, GroupLayout.PREFERRED_SIZE) .addPreferredGap(ComponentPlacement.RELATED) .addComponent(layeredPane, GroupLayout.PREFERRED_SIZE, 95, GroupLayout.PREFERRED_SIZE) .addPreferredGap(ComponentPlacement.RELATED) .addComponent(layeredPane_2, GroupLayout.DEFAULT_SIZE, 63, Short.MAX_VALUE)) ); // JButton button = new JButton(); JButton button = new JButton(); button.setBounds(10, 11, 97, 23); layeredPane_2.add(button); button.addActionListener(new ActionListener() {
//////////////////////// IMPLEMENTAÇÃO DO BOTÃO SALVAR NO BANCO DE DADOS //////////////////////////////
public void actionPerformed(ActionEvent arg0) {
try {
Connection con = Conexao.faz_conexao();
String sql = "insert into produto(cod_produto, descricao, cod_barras) values (?,?,?)";
PreparedStatement stmt = con.prepareStatement(sql);
stmt.setString(1, codigo_produto.getText());
stmt.setString(2, descricao_produto.getText());
stmt.setString(3, codigo_barras.getText());
stmt.execute();
stmt.close();
con.close();
JOptionPane.showMessageDialog(null, "Produto cadastrado!");
}catch (Exception e){
e.printStackTrace();
// JOptionPane.showMessageDialog(null,"Erro de Conexão com o Banco! "+e,".:: Erro ::.",JOptionPane.ERROR_MESSAGE);
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
}
});
button.setText("Cadastrar");
jButton1 = new javax.swing.JButton();
jButton1.setBounds(128, 11, 69, 23);
layeredPane_2.add(jButton1);
jButton1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
}
});
jButton1.setText("Editar");
jButton2 = new javax.swing.JButton();
jButton2.setBounds(207, 11, 72, 23);
layeredPane_2.add(jButton2);
jButton2.setText("Excluir");
jLabel2 = new javax.swing.JLabel();
jLabel2.setBounds(10, 11, 96, 14);
layeredPane_1.add(jLabel2);
jLabel2.setText("C\u00F3digo produto");
codigo_produto = new javax.swing.JTextField();
codigo_produto.setBounds(10, 29, 153, 27);
layeredPane_1.add(codigo_produto);
jLabel3 = new javax.swing.JLabel();
jLabel3.setBounds(232, 11, 180, 14);
layeredPane_1.add(jLabel3);
jLabel3.setText("Descrição do produto");
descricao_produto = new javax.swing.JTextField();
descricao_produto.setBounds(232, 31, 161, 25);
layeredPane_1.add(descricao_produto);
jLabel5 = new javax.swing.JLabel();
jLabel5.setBounds(10, 79, 136, 14);
layeredPane_1.add(jLabel5);
jLabel5.setText("Local de armazenagem");
local_armazenagem = new javax.swing.JTextField();
local_armazenagem.setBounds(10, 104, 153, 27);
layeredPane_1.add(local_armazenagem);
JLabel lblCdigoDeBarras = new JLabel("C\u00F3digo de barras");
lblCdigoDeBarras.setBounds(232, 81, 114, 14);
layeredPane_1.add(lblCdigoDeBarras);
codigo_barras = new JTextField();
codigo_barras.setBounds(232, 104, 161, 27);
layeredPane_1.add(codigo_barras);
jLabel1 = new javax.swing.JLabel();
jLabel1.setBounds(10, 25, 124, 14);
layeredPane.add(jLabel1);
jLabel1.setText("Código do fornecedor");
codigo_fornecedor = new javax.swing.JTextField();
codigo_fornecedor.setBounds(10, 43, 104, 28);
layeredPane.add(codigo_fornecedor);
jLabel4 = new javax.swing.JLabel();
jLabel4.setBounds(219, 23, 193, 14);
layeredPane.add(jLabel4);
jLabel4.setText("Fornecedor");
fornecedor = new javax.swing.JTextField();
fornecedor.setBounds(219, 43, 193, 28);
layeredPane.add(fornecedor);
getContentPane().setLayout(layout);
pack();
}// </editor-fold>
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(Cadastro_produtos.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(Cadastro_produtos.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(Cadastro_produtos.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(Cadastro_produtos.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new Cadastro_produtos().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
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.JTextField codigo_fornecedor;
private javax.swing.JTextField codigo_produto;
private javax.swing.JTextField descricao_produto;
private javax.swing.JTextField fornecedor;
private javax.swing.JTextField local_armazenagem;
private JTextField codigo_barras;
private JLayeredPane layeredPane_2;
}