0

So my code worked yesterday but after building and cleaning it, it no longer works. Netbeans says it is unable to find and load the main class. I have not changed any of the code since running it yesterday, so the code isn't the problem. I have cleared the cache, renamed my project and folders, and copy/pasted original code into a new project. I have used a different version of netbeans and it says the same thing. When I go into properties, it does not have my main class as an option. Any help would be greatly appreciated!!

public class MyClass extends JFrame {

/**
 *
 */
public MyClass()  { 

       initComponents();
}
@SuppressWarnings("unchecked")

private void initComponents() {


       JFrame frame1 = new JFrame ();
       JPanel jp1 = new JPanel ();
       frame1.getContentPane().add(jp1);

    jLabel1 = new javax.swing.JLabel();
    jp1.add(jLabel1);
    jLabel2 = new javax.swing.JLabel();




etc...





public static void main(String args[]) {

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

    java.awt.EventQueue.invokeLater(() -> {
        new MyClass().setVisible(true);
    });
}

Requested Picture Requested Picture 2

Update: I have narrowed it down to something small in my code for Action performed. Any ideas? I've gone through it with a fine toothed comb and all brackets and semi colons are accounted for. There are also no red lines (error indicators).

  • I'd rather you show us the main class so we can affirm that it is in fact not the main class and a configuration problem, as we can then use the working main class to address the configuration problem. – Compass Jun 24 '16 at 20:59
  • 1
    Find the class in your project that you are expecting to be the main class and look if the `main` method actually exists and if so, examine the signature. – Glenn Jun 24 '16 at 21:00
  • Possibly missing a bracket in the code you posted. Put your main first in the class declaration for sanity purposes at the very least, and see if that changes anything. – Compass Jun 24 '16 at 21:06
  • Can you show us a picture of your IDE? If I'm not wrong there's an option when you right clic on the file that allows you to make that class the main one. Probably you changed that property to another class. (Show the console when it says that about no main class and your project tree please). – Frakcool Jun 24 '16 at 21:08
  • @Compass I'm not sure what you mean by put the main class first – Victoria Jun 24 '16 at 21:09
  • Cut and paste it right after you declare your class. If there's a bracket issue, i.e. if it's hiding in an anonymous class, this would fix it. – Compass Jun 24 '16 at 21:13
  • Build the project and find the classes that are output (or the resultant JAR) and interrogate this class (or class within jar) with javap to see if the main() method is defined. Make sure that your main method is the first method in your class too. Sounds like a simple scope or cache issue. – ManoDestra Jun 24 '16 at 21:17
  • @Compass No luck. There is a bracket at the very bottom of my actual code (not all of it is posted here) if that's what you're worried about. – Victoria Jun 24 '16 at 21:17
  • @ManoDestra I'm new to java. Could you say that again but very explicitly? – Victoria Jun 24 '16 at 21:18
  • Look in the directories for where your classes are output, in this case, MyClass.class. Then, you can interrogate its public method signatures by calling javap MyClass, providing it's in the root package. Look up [how to use javap](http://docs.oracle.com/javase/7/docs/technotes/tools/windows/javap.html). It's a very useful tool. If the class does not contain a public static void main(String[] args) method signature, then it won't be considered as a potential main class. – ManoDestra Jun 24 '16 at 21:23
  • I don't see your project there. I want to see the main window of NetBeans @Victoria where I can see this code, on the left the files and on the bottom the console. Please show that – Frakcool Jun 24 '16 at 21:24
  • @ManoDestra I'm still very confused – Victoria Jun 24 '16 at 21:31
  • If you google "Netbeans Error: could not find or load main class" you'll find many possibly relevant links. Have you tried any of those? – Klitos Kyriacou Jun 24 '16 at 21:57
  • @KlitosKyriacou I've tried all of them, which is why this question is here lol. I'm out of ideas. – Victoria Jun 25 '16 at 03:17
  • 2
    Is this happening for just this particular project? If so, try creating a new project from scratch. Then create a new class in the new project, and copy and paste the text of the code into the new class. If that works, delete the old project. – Klitos Kyriacou Jun 25 '16 at 09:36
  • @KlitosKyriacou No luck. I also tried making a new project with three classes. The first is the main class that sets frame 1 visible. The second and third are frames 1 and 2. Netbeans tells me that it cannot find a class for frame 1, so I think there is a problem with the format of my code for frame 1. – Victoria Jun 27 '16 at 14:36

0 Answers0