Toda vez que eu executo o código abaixo aparece o seguinte erro...
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at inserirCadastro_prof.actionPerformed(inserirCadastro_prof.java:17)
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.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)
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
import java.sql.*;
public class inserirCadastro_prof implements ActionListener{
public interface_3_prof campos;
public Connection conecta;
public inserirCadastro_prof(Connection d, interface_3_prof a){
campos=a;
conecta=d;
}
public void actionPerformed(ActionEvent e){
try{
Statement executaSQL=conecta.createStatement();
if(!campos.nome_prof.getText().equals("")){
String query="INSERT INTO professor(nm_prof,tel_prof,end_prof) VALUES( '"+campos.nome_prof.getText()+
"','"+campos.tel_prof.getText()+
"','"+campos.end_prof.getText()+
"')";
int result = executaSQL.executeUpdate(query);
if (result==1){
System.out.println("Inserido \n");
campos.nome_prof.setText("");
campos.tel_prof.setText("");
campos.end_prof.setText("");
}
else{
System.out.println("Erro \n");
campos.nome_prof.setText("");
campos.tel_prof.setText("");
campos.end_prof.setText("");
}
}
else
JOptionPane.showMessageDialog(null, "PREENCHA OS CAMPOS","Atenção",JOptionPane.ERROR_MESSAGE);
executaSQL.close();
}
catch(SQLException sqlex){
sqlex.printStackTrace();
System.out.println(sqlex.toString());
}
}
}
