Olá pessoas.
Recentemente voltei a programar (em java) e baixei o NetBeans pra ver o que eu ainda sabia fazer. Desenvolvi até bastante coisa, mas sempre que eu compilava QUALQUER projeto, ao tentar abrir com dois clicks dava o erro "Could not find the main class:nomedoprojeto.NomeDoProjeto. Program will exit.", no entanto, se eu for pelo prompt e usar "java -jar NomeDoArquivo.jar" ele executa normalmente sem erro.
Comecei com a versão 7.2 do NetBeans, cacei na internet e vi algumas pessoas falando que o erro era por culpa dela, voltei pra versão 7.1.2, o erro persistiu, comecei a olhar outros tópicos e vi sobre setar as Variáveis de Ambiente e, mesmo sabendo que já tinha feito tudo certo (CLASSPATH, PATH, JAVA_HOME e JRE_HOME setado) o erro persistia, por isso foi a segunda coisa que eu olhei, já sabia que esse não deveria ser o problema, até mesmo pq os arquivos executam pelo prompt.
Estou meio cansado de procurar sobre o assunto e não conseguir uma solução para o problema.
Alguém tem uma solução?
Lembrando, minhas Variáveis de Ambiente estão todas corretas, também já mudei a classe principal do projeto pelo NetBeans e compilei várias vezes, java está atualizado. Realmente não sei o que fazer. Também tentei executar e programar os mesmos projetos pelo Fedora KDE 17. Da o mesmo erro.
Espero ter deixar o mais claro possível. Vou deixar o código de um dos projetos mais básicos aqui pra vcs verem que não é erro dele, até pq ele executa tanto no NetBeans quanto pelo comando "java -jar".
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package projetoonclick;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
/**
*
* @author joselric
*/
public class FButtom extends javax.swing.JFrame {
/**
* Creates new form FButtom
*/
public FButtom() {
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.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jBtOk = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jBtOk.setText("Click");
jBtOk.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jBtOkActionPerformed(evt);
}
});
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(33, 33, 33)
.addComponent(jBtOk)
.addContainerGap(34, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(25, 25, 25)
.addComponent(jBtOk)
.addContainerGap(25, Short.MAX_VALUE))
);
pack();
}// </editor-fold>
private void jBtOkActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
JOptionPane.showMessageDialog(null, "O botão está funcionando");
}
/**
* @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(FButtom.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(FButtom.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(FButtom.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(FButtom.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/*
* Create and display the form
*/
java.awt.EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
new FButtom().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton jBtOk;
// End of variables declaration
}
e ProjetoOnClick.java
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package projetoonclick;
/**
*
* @author joselric
*/
public class ProjetoOnClick {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
java.awt.EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
new FButtom().setVisible(true);
}
});
}
}
p.s.: não sei pq eu dei esse nome pro projeto.