[RESOLVIDO] Problema com Construção .jar

Olá, criei um projeto simples de cadastro em banco de dados (Postgresql) com uma tela de login sendo a tela inicial, porem quando eu mando limpar e executar ele cria o arquivo .jar na pasta porem quando eu clico ele não executa e nem faz nada … alguém poderia me ajudar ??

OBS: Minha classe marcada como principal é o formulário Jframe (o formulário de login).

Provavelmente você não está exportando alguma dependência junto (ou não copia a pasta com as dependências que o nb cria).
Mas, uma forma de ver o erro é executar via prompt de comando/terminal

java -jar NOME_DO_TEU_JAR.jar

Recebi o seguinte resultado :

C:\Users\felipe.schmidt\Documents\NetBeansProjects\ControleMensal\store> java -jar ControleMensal.jar
Exception in thread “main” java.lang.NullPointerException
at javax.swing.ImageIcon.(Unknown Source)
at controlemensal.Login.initComponents(Login.java:90)
at controlemensal.Login.(Login.java:27)
at controlemensal.Main.main(Main.java:19)
PS C:\Users\felipe.schmidt\Documents\NetBeansProjects\ControleMensal\store>

O que tem na linha 90 da classe Login?

jLabel3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/icons8-usuário-64.png")));

Ou jLabel3 está nulo ou não encontra a imagem referida.

A imagem esta na pasta mas eu não sei ver se a jlabel3 esta nula pois ela aparece no meu projeto

Uma outra coisa engraçada é essa parte:

não existe essa classe no meu projeto.

Não existe uma classe chamada Main dentro do package controlemensal?

Não , são só essas classes.

image

Refiz esse teste e me devolveu assim:

    Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
    at sun.awt.SunToolkit.getImageFromHash(Unknown Source)
    at sun.awt.SunToolkit.getImage(Unknown Source)
    at controlemensal.Login.setIcon(Login.java:35)
    at controlemensal.Login.<init>(Login.java:30)
    at controlemensal.Login.lambda$main$0(Login.java:310)
    at java.awt.event.InvocationEvent.dispatch(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.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)

Não é um teste, é a maneira de executar usando prompt.

E o que tem na linha 35? Posta a classe toda e indica o que tem na linha 35

Linha 35 /

private void setIcon() {
     setIconImage(Toolkit.getDefaultToolkit().getImage(getClass().getResource("../img/icofav.png")));
}

package controlemensal;

    import Entidades.conectabd;
    import java.awt.Toolkit;
    import java.awt.event.KeyEvent;
    import java.sql.*;
    import java.util.logging.Level;
    import java.util.logging.Logger;
    import javax.swing.JOptionPane;




public class Login extends javax.swing.JFrame {

Connection con;
PreparedStatement pst;
ResultSet rs;


public Login() throws ClassNotFoundException {
    initComponents();
    con = conectabd.conectadb();    
    jTextField1.requestFocus();
    setIcon();
    
    
}
private void setIcon() {
     setIconImage(Toolkit.getDefaultToolkit().getImage(getClass().getResource("../img/icofav.png")));
}
    public void log() throws ClassNotFoundException{
        String sql = "select * from login where usuario = ? and senha = ?";
        try {
            pst = con.prepareStatement(sql);
            pst.setString(1,jTextField1.getText());
            pst.setString(2,jPasswordField1.getText());
            rs = pst.executeQuery();
            
            if(rs.next()){
                PreHome n = new PreHome();
                n.setVisible(true);
                this.dispose();
                
            }
            
            else{
                   JOptionPane.showMessageDialog(null,"Usuario Invalido");
            }
            
        } catch (SQLException erro) {
            
            JOptionPane.showMessageDialog(null,erro);
        }
    }        
        
        
    
/**
 * 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() {

    jLabel1 = new javax.swing.JLabel();
    jLabel2 = new javax.swing.JLabel();
    jLabel3 = new javax.swing.JLabel();
    jLabel4 = new javax.swing.JLabel();
    jTextField1 = new javax.swing.JTextField();
    jPasswordField1 = new javax.swing.JPasswordField();
    jButton1 = new javax.swing.JButton();
    jButton2 = new javax.swing.JButton();

    jLabel1.setText("jLabel1");

    setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
    setUndecorated(true);

    jLabel2.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
    jLabel2.setText("Efetue o Login");

    jLabel3.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
    jLabel3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/icons8-usuário-64.png"))); // NOI18N
    jLabel3.setText("Usuario");

    jLabel4.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
    jLabel4.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/icons8-senha-64.png"))); // NOI18N
    jLabel4.setText("Senha");

    jTextField1.setToolTipText("Digite o seu Usuario");
    jTextField1.addFocusListener(new java.awt.event.FocusAdapter() {
        public void focusGained(java.awt.event.FocusEvent evt) {
            jTextField1FocusGained(evt);
        }
        public void focusLost(java.awt.event.FocusEvent evt) {
            jTextField1FocusLost(evt);
        }
    });
    jTextField1.addKeyListener(new java.awt.event.KeyAdapter() {
        public void keyTyped(java.awt.event.KeyEvent evt) {
            jTextField1KeyTyped(evt);
        }
    });

    jPasswordField1.setToolTipText("Digite sua Senha");
    jPasswordField1.addFocusListener(new java.awt.event.FocusAdapter() {
        public void focusLost(java.awt.event.FocusEvent evt) {
            jPasswordField1FocusLost(evt);
        }
    });
    jPasswordField1.addKeyListener(new java.awt.event.KeyAdapter() {
        public void keyPressed(java.awt.event.KeyEvent evt) {
            jPasswordField1KeyPressed(evt);
        }
        public void keyTyped(java.awt.event.KeyEvent evt) {
            jPasswordField1KeyTyped(evt);
        }
    });

    jButton1.setBackground(new java.awt.Color(0, 153, 0));
    jButton1.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
    jButton1.setForeground(new java.awt.Color(255, 255, 255));
    jButton1.setText("Login");
    jButton1.setEnabled(false);
    jButton1.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            jButton1ActionPerformed(evt);
        }
    });

    jButton2.setText("X");
    jButton2.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            jButton2ActionPerformed(evt);
        }
    });

    javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
    getContentPane().setLayout(layout);
    layout.setHorizontalGroup(
        layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
            .addContainerGap(170, Short.MAX_VALUE)
            .addComponent(jLabel2)
            .addGap(129, 129, 129))
        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
            .addGap(0, 0, Short.MAX_VALUE)
            .addComponent(jButton2))
        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
            .addContainerGap()
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                .addGroup(layout.createSequentialGroup()
                    .addGap(0, 0, Short.MAX_VALUE)
                    .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 88, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGroup(layout.createSequentialGroup()
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(jLabel3)
                        .addComponent(jLabel4))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(jTextField1)
                        .addComponent(jPasswordField1))))
            .addGap(28, 28, 28))
    );
    layout.setVerticalGroup(
        layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(layout.createSequentialGroup()
            .addComponent(jButton2)
            .addGap(10, 10, 10)
            .addComponent(jLabel2)
            .addGap(27, 27, 27)
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(jLabel3)
                .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addGap(18, 18, 18)
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(jLabel4)
                .addComponent(jPasswordField1, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addComponent(jButton1)
            .addContainerGap(23, Short.MAX_VALUE))
    );

    setSize(new java.awt.Dimension(414, 288));
    setLocationRelativeTo(null);
}// </editor-fold>                        

private void jPasswordField1FocusLost(java.awt.event.FocusEvent evt) {                                          
    if  (jPasswordField1.getText().equals("")){
        jLabel4.setForeground(new java.awt.Color(255, 0, 0));
        jButton1.setEnabled(false);
    } 
    else
        if(!jPasswordField1.getText().equals("")){
          jButton1.setEnabled(true);  
        }
    else{
           

    }
    
}                                         

private void jPasswordField1KeyTyped(java.awt.event.KeyEvent evt) {                                         
   //jButton1.setEnabled(true);
     jLabel4.setForeground(new java.awt.Color(0, 0, 0));
      if(jTextField1.getText().equals("Usuario não pode ser em branco")  || jTextField1.getText().equals("")){
          jButton1.setEnabled(false);
        jTextField1.setText("Usuario não pode ser em branco");
        jTextField1.setForeground(new java.awt.Color(255, 0, 0));
       jLabel3.setForeground(new java.awt.Color(255, 0, 0));
      }
      
      else{jButton1.setEnabled(true);}
}                                        

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
    try {
        log();
    } catch (ClassNotFoundException ex) {
        Logger.getLogger(Login.class.getName()).log(Level.SEVERE, null, ex);
    }
}                                        

private void jTextField1FocusLost(java.awt.event.FocusEvent evt) {                                      
     if  (jTextField1.getText().equals("")){
        jButton1.setEnabled(false);
        jTextField1.setText("Usuario não pode ser em branco");
        jTextField1.setForeground(new java.awt.Color(255, 0, 0));
       jLabel3.setForeground(new java.awt.Color(255, 0, 0));
    }
     else
         if(jTextField1.getText().equals("Usuario não pode ser em branco")){
             jTextField1.setText("");
             jButton1.setEnabled(false);
         }
    else{
        
    }
}                                     

private void jTextField1FocusGained(java.awt.event.FocusEvent evt) {                                        
    if(jTextField1.getText().equals("Usuario não pode ser em branco")){
        jTextField1.setText("");
    }
    else{
        
    }
}                                       

private void jTextField1KeyTyped(java.awt.event.KeyEvent evt) {                                     
   
        jTextField1.setForeground(new java.awt.Color(0, 0, 0));
        jLabel3.setForeground(new java.awt.Color(0, 0, 0));
}                                    

private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {                                         
   this.dispose();
}                                        

private void jPasswordField1KeyPressed(java.awt.event.KeyEvent evt) {                                           
   if(evt.getKeyCode()==KeyEvent.VK_ENTER){
       try {
           log();
       } catch (ClassNotFoundException ex) {
           Logger.getLogger(Login.class.getName()).log(Level.SEVERE, null, ex);
       }
   }
}                                          

/**
 * @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(Login.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    } catch (InstantiationException ex) {
        java.util.logging.Logger.getLogger(Login.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    } catch (IllegalAccessException ex) {
        java.util.logging.Logger.getLogger(Login.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    } catch (javax.swing.UnsupportedLookAndFeelException ex) {
        java.util.logging.Logger.getLogger(Login.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    }
    //</editor-fold>
    //</editor-fold>

    /* Create and display the form */
    java.awt.EventQueue.invokeLater(() -> {
        try {
            new Login().setVisible(true);
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(Login.class.getName()).log(Level.SEVERE, null, ex);
        }
    });
}

// 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.JPasswordField jPasswordField1;
private javax.swing.JTextField jTextField1;
// End of variables declaration                   

}

Resolvido o erro , era simplesmente o caminho que não estava encontrando , resolvi colocando a imagem no pacote principal do programa e funcionou perfeitamente