0

introducir la descripción de la imagen aquí error Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException

package vista;

import Modelo.Conexion;
import Objetos.Usuario;
import controladores.UsuariosController;
import java.awt.HeadlessException;
import java.sql.SQLException;
import javax.swing.JOptionPane;
import org.apache.commons.codec.digest.DigestUtils;

/**
 *
 * @author 
 */
public class InicioSesion extends javax.swing.JFrame {

private String direccion = "localhost";

public InicioSesion() {
    initComponents();
    setLocationRelativeTo(null);
    setResizable(false);
}

public void iniciarSesion() {
    String nombre = usuario.getText();
    String password = contraseña.getText();

    try {
        Conexion.iniciarConexion(direccion, "sepan", "root", "");
        // Usuario usuario = UsuariosController.getUsuario(nombre, DigestUtils.md5Hex(password));
        Usuario usuario = UsuariosController.getUsuario(nombre, password);

        if (usuario != null) {
            JOptionPane.showMessageDialog(null, "Logeo exitoso");
            JOptionPane.showMessageDialog(null, "Bienvenido " + nombre + "\nHas Ingresado al Sistema de Salones", "Mensaje de bienvenida", JOptionPane.INFORMATION_MESSAGE);

            Menu_1.correr(usuario);
            dispose();

        } else {
            JOptionPane.showMessageDialog(null, "Sus datos son incorrectos, reviselos");
        }

    } catch (SQLException | HeadlessException e) {
        e.printStackTrace();
        JOptionPane.showMessageDialog(null, "Problema con la conexion... Revise los datos de su servidor.");
    }
}

/**
 * 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.
 */
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">                          
private void initComponents() {

    jPanel1 = new javax.swing.JPanel();
    jLabel4 = new javax.swing.JLabel();
    usuario = new javax.swing.JTextField();
    jLabel1 = new javax.swing.JLabel();
    contraseña = new javax.swing.JPasswordField();
    jLabel2 = new javax.swing.JLabel();
    jButton1 = new javax.swing.JButton();
    lblHide = new javax.swing.JLabel();
    jLabel3 = new javax.swing.JLabel();

    setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
    setLocation(new java.awt.Point(0, 0));

    jPanel1.setBackground(new java.awt.Color(0, 255, 255));
    jPanel1.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
    jPanel1.setToolTipText("");

    jLabel4.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagenes/UNID.jpg"))); // NOI18N

    jLabel1.setText("Usuario");

    contraseña.setForeground(new java.awt.Color(102, 102, 255));

    jLabel2.setText("Contraseña");

    jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Img/icons8-entrar-32.png"))); // NOI18N
    jButton1.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            jButton1ActionPerformed(evt);
        }
    });

    lblHide.setText("Conectar a: " + direccion);

    jLabel3.setFont(new java.awt.Font("Tahoma", 2, 10)); // NOI18N
    jLabel3.setForeground(new java.awt.Color(0, 0, 255));
    jLabel3.setText("Cambiar servidor...");
    jLabel3.addMouseListener(new java.awt.event.MouseAdapter() {
        public void mouseClicked(java.awt.event.MouseEvent evt) {
            jLabel3MouseClicked(evt);
        }
    });

    javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
    jPanel1.setLayout(jPanel1Layout);
    jPanel1Layout.setHorizontalGroup(
        jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
            .addContainerGap()
            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(jLabel2)
                .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 56, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addGap(18, 18, 18)
            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel1Layout.createSequentialGroup()
                    .addGap(0, 0, Short.MAX_VALUE)
                    .addComponent(jLabel4)
                    .addGap(97, 97, 97))
                .addGroup(jPanel1Layout.createSequentialGroup()
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(contraseña, javax.swing.GroupLayout.PREFERRED_SIZE, 180, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(usuario, javax.swing.GroupLayout.PREFERRED_SIZE, 180, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGap(0, 0, Short.MAX_VALUE))))
        .addGroup(jPanel1Layout.createSequentialGroup()
            .addGap(130, 130, 130)
            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(lblHide, javax.swing.GroupLayout.PREFERRED_SIZE, 246, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addComponent(jLabel3)
                .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)))
    );
    jPanel1Layout.setVerticalGroup(
        jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(jPanel1Layout.createSequentialGroup()
            .addContainerGap()
            .addComponent(jLabel4)
            .addGap(18, 18, 18)
            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(usuario, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addComponent(jLabel1))
            .addGap(18, 18, 18)
            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                .addComponent(contraseña, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addComponent(jLabel2))
            .addGap(18, 18, 18)
            .addComponent(lblHide)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addComponent(jLabel3)
            .addGap(18, 18, 18)
            .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
    );

    javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
    getContentPane().setLayout(layout);
    layout.setHorizontalGroup(
        layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addComponent(jPanel1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
    );
    layout.setVerticalGroup(
        layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(layout.createSequentialGroup()
            .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addGap(0, 0, Short.MAX_VALUE))
    );

    pack();
}// </editor-fold>                        

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
    iniciarSesion();
}                                        

private void jLabel3MouseClicked(java.awt.event.MouseEvent evt) {                                     
    CambiarServer.correr(direccion, this);
}                                    

public void setDirección(String dirección) {
    this.direccion = dirección;
    lblHide.setText("Conectar a: " + direccion);
}
/**
 * @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(InicioSesion.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    } catch (InstantiationException ex) {
        java.util.logging.Logger.getLogger(InicioSesion.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    } catch (IllegalAccessException ex) {
        java.util.logging.Logger.getLogger(InicioSesion.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    } catch (javax.swing.UnsupportedLookAndFeelException ex) {
        java.util.logging.Logger.getLogger(InicioSesion.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 InicioSesion().setVisible(true);
        }
    });
}

// Variables declaration - do not modify                     
private javax.swing.JPasswordField contraseña;
private javax.swing.JButton jButton1;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JPanel jPanel1;
private javax.swing.JLabel lblHide;
private javax.swing.JTextField usuario;
// End of variables declaration                   
E. Betanzos
  • 4,619
  • 1
  • 7
  • 23

1 Answers1

0

El error está en que una de estas dos llamadas devuelven null, la que esté en la linea 82:

getClass().getResource("/imagenes/UNID.jpg")

o

getClass().getResource("/Img/icons8-entrar-32.png")

Esto suele deberse a que la ruta del recurso no es correcta.

Mira la documentación del método para que entiendas como funciona, aquí paar java 8 y aquí para Java 9. Son casi idénticas, pero en Java 9 con el tema de los módulos varía un poco.

E. Betanzos
  • 4,619
  • 1
  • 7
  • 23