Discussion:
netbeans 6.5 "No main classes found"
bdeeming
2010-08-13 06:44:53 UTC
Permalink
I've had this same problem at least twice now when using NetBeans 6.9. To fix it this most recent time the only solution was to right click the .java file in the project browser and Refactor>rename it to something different, the rename it again back to its original name.
Note that it did not only effect the main class for me this most recent time. After doing the above for my main class, i then ran the project and it loaded that class, plus one other class fine, but not a third. I then did the rename drill for this class file as well and all was well.
Hope this is helpful to someone, or anyone who is trying to identify where exactly the bug in NetBeans lies.

Ben
Christine
2010-09-07 18:07:11 UTC
Permalink
I am experiencing a similar issue as this original post.

Last week, I walked through the CarsApp tutorial (http://netbeans.org/kb/docs/java/gui-db.html) and it ran just fine. Today, when I try to run it, I get a "no main class found" error. As far as I can tell, there hasn't been any changes to the main program (although I suspect a possible syntax error or something less obvious to me).

I am using version 6.8, I have checked that the CarsApp is the main program when running. I also reread the tutorial and created another demo that ran OK and then did a diff on the old and new; I could not find any differences in the code. (The only difference I found between the two was in the Compile Classpath and Runtime Classpath, but I am not sure how to change it to make them the same. I right-clicked on the .java file and clicked properties.)

The following is the code:


/*
* CarsApp.java
*/

package carsapp;

import org.jdesktop.application.Application;
import org.jdesktop.application.SingleFrameApplication;

/**
* The main class of the application.
*/
public class CarsApp extends SingleFrameApplication {

/**
* At startup create and show the main frame of the application.
*/
@Override protected void startup() {
show(new CarsView(this));
}

/**
* This method is to initialize the specified window by injecting resources.
* Windows shown in our application come fully initialized from the GUI
* builder, so this additional configuration is not needed.
*/
@Override protected void configureWindow(java.awt.Window root) {
}

/**
* A convenient static getter for the application instance.
* @return the instance of CarsApp
*/
public static CarsApp getApplication() {
return Application.getInstance(CarsApp.class);
}

/**
* Main method launching the application.
*/
public static void main(String[] args) {
launch(CarsApp.class, args);
}
}

Any help would be greatly appreciated. Thank you!
Chris
Franz
2010-09-08 13:02:05 UTC
Permalink
Hi christine,
Post by Christine
I am experiencing a similar issue as this original post.
Last week, I walked through the CarsApp tutorial (http://netbeans.org/kb/docs/java/gui-db.html) and it ran just fine. Today, when I try to run it, I get a "no main class found" error. As far as I can tell, there hasn't been any changes to the main program (although I suspect a possible syntax error or something less obvious to me).
I am using version 6.8, I have checked that the CarsApp is the main program when running. I also reread the tutorial and created another demo that ran OK and then did a diff on the old and new; I could not find any differences in the code. (The only difference I found between the two was in the Compile Classpath and Runtime Classpath, but I am not sure how to change it to make them the same. I right-clicked on the .java file and clicked properties.)
have you tried renaming the class like the original poster?

regards
fg
jomamas
2010-09-12 21:13:00 UTC
Permalink
Guys I had the same problem.

Turns out - the build directory of my classes was being erased upon execution. But - the classes in the src/classes/ directory that was in a directory named the same as a project were left intact. So if your project is called 'myproject' then

src/classes/myproject/ will remain at exec, but
src/classes/otherdir/ will be deleted

if your classes are in some other dir they will be erased. So basically - the first part of your package path needs to be named the same name as your project. There are other changes to your .properties file you can make to ammend this - but this was the crux of it for me.
Honeysery
2010-09-28 06:12:47 UTC
Permalink
If you don't want to go through all this trouble, there is a way out for you to dive straight into the excitement of(RuneScape Gold (http://www.storeingame.com)) World of Warcraft, that is, by purchasing a veteran account. A WOW(RS Gold (http://www.gobuycheaprsgold.com)) veteran account is an advanced character in the game. Some other player has gone through all the trouble in building(RuneScape Gold (http://www.rsfarming.com/)) up. In other words, it's a character with all the skill and reputation; you're looking for(Buy WOW Gold (http://www.zyy.com)) other professional. Along with the character, you come to the account. Hence, all the wealth and possessions come along with the character. You have the ability to dive straight into the higher level of the game.
fable187
2010-10-06 04:58:23 UTC
Permalink
Yeah, every time I try to run the project, it tells me it has no main class. That's because the main class file is not in the same folder as the executable it keeps making. so just find the fold it builds the executable and copy/paste your code in the same folder .. bam it works!

I figured it out by right clicking the main project at the top of the tree, then clicking on: Clean and Build

Then going to the directory it tells me the .jar file is, then copying the code files i made to that directory. and bam my program works
bdeeming
2010-10-06 05:37:52 UTC
Permalink
Im not sure that I see how that can work. The code files you speak of are the .java files I assume... However the final jar archive should only require compiled .class files within it, thus adding the .java files should have no effect what soever.
If you are instead referring to the compiled .class files found in the build directory of the project, then thats something quite interesting - that said however, at a guess I would say that NetBeans would be attempting to find the main class from the build directory already and not the dist directory. The dist directory to the best of my knowledge is simply for an easy means of creating a distributable copy of the application, and nothing much else.
Fogy
2010-10-20 06:49:20 UTC
Permalink
<rant> [Evil or Very Mad]

This is the most ridiculous thing.

After hours of working on a project I finally get to my final version and I go to test run it and bam, no main classes found after running it all day long. I'm freakin done and I'd like to actually finish my final exam please!!

This has been going on for YEARS, according the the google. What the hell is NetBeans doing? What's the difficulty of A) NOT losing track of, oh, say, the freakin the main I'm looking at right in front of me and B) GIVING a way to manualy fix their f-up?!

I've reinstalled NotWorthBeans, renamed files, resaved files, refactored, removed folders and all the other "re's" out there and I can't as much as debug my work.

Where's the fix, NetBeans? It's not like you don't know how to write code.

</rant>


Is there ANYTHING that works?
Franz
2010-10-21 20:01:34 UTC
Permalink
<rant> [removed useless part of the message]
</rant>
Is there ANYTHING that works?
Maybe one of the solutions of
http://frickelblog.wordpress.com/2010/04/30/no-main-class-found/
helps.
fizzad
2010-10-25 02:56:20 UTC
Permalink
I just had this same problem and solved it by making sure the class with my main method is under the source package folders. This can be accomplished by right clicking on your project selecting properties and looking under sources.

I realize this is an old post but wanted to proved the solution I found incase the problem is seen again by others.
Continue reading on narkive:
Loading...