Tengo un problema al conectarme al gestor de mi base de datos, aparece el error:
"AWT-EventQueue-0" java.lang.NullPointerException
Cuando envío un objeto a la clase que los interpreta y guarda en una base de datos MYSQL.
Lo que hace este código es crear un objeto Campeonato
a base de los campos que se encuentran en la ventana, el objeto se crea correctamente (ya que lo muestro en un syso), sin embargo al intentar guardarlo con el preparedStatement
no se guarda de ninguna manera.
Error:
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at basesDeDatos.GestorBD.gJuez(GestorBD.java:142)
at campeonato.VentanaSignIn$2.actionPerformed(VentanaSignIn.java:436)
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$500(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$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.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$JavaSecurityAccessImpl.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)
Este es el código del gestor:
//GUARDAR CAMPEONATO
public void gCrearCampeonato(Campeonato c) throws BDexception {
try {
pStatement = conn.prepareStatement("INSERT INTO campeonato VALUES (default, ?, ?, ?, null, ?, null, ?)");
pStatement.setString(1, c.getNombre());
pStatement.setString(2, c.getLugar());
pStatement.setString(3, c.getF_inicio());
pStatement.setString(4, c.getPatr_princ());
pStatement.setInt(5, c.getCoste());
pStatement.executeUpdate();
} catch (SQLException e) {
throw new BDexception("Error al crear el campeonato", e);
}
}
-- -
Esta es la parte de código que llama al gCrearCampeonato
:
protected Connection conn = null;z
btnCrearCampeonato.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
DateFormat df = new SimpleDateFormat("dd/MM/yy");
Calendar calobj = Calendar.getInstance();
String nombre = txtNombreCamp.toString();
String lugar = txtLugar.toString();
String f_inicio = df.format(calobj.getTime());
String f_fin = null;
String patr_princ = comboPatrocinador.getSelectedItem().toString();
int coste = Integer.parseInt(txtCoste.getText());
int recaudacion = 0;
int ganancia = 0;
Manga[] mangas = null;
Campeonato c = new Campeonato(nombre, lugar, f_inicio, f_fin, patr_princ, coste, recaudacion, ganancia, mangas);
System.out.println("patata");
try {
gestor.gCrearCampeonato(c);
} catch (BDexception e1) {
e1.printStackTrace();
}
}
});