Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Main class not recognized

 
Kevan Ryan
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey Javaranchers,

For some reason, the NetBeans IDE does not recognize the main class within my program. I thought that there was a way to set an object class as a 'main', but I'm not entirely sure. Is any requirement the main class needs to have, so that it is recognized?

Thanks in advance!
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It must have a method with this signature:

public static void main (String[] args)
 
Kevan Ryan
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeah, that's what I figured too, but it still doesn't seem to recognize it. Here is my entire program posted, but I feel that the mistake I'm making is just a small thing that slip out of my mind.

Thanks!



 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24211
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So how do you mean, it's not recognized? Just checking: the "main()" in the "Main" class above doesn't actually do anything at all, so if you ran it, it would immediately exit with no effect. You know that, right?
 
Kevan Ryan
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeah, I realize that right now the 'main' class does nothing. But I don't know where to go from here.

Right now the NetBeans IDE won't run the program because it says that my package has no Main class. And even with the 'main class to nowhere', it still doesn't run. It's pretty frustrating, considering that my program is finished but this error is keeping me from actually running it.


EDIT: It turns out I did end up making a silly mistake - I forgot to put the other object classes inside my main class. Thanks for all who helped!
 
Colin Wright
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's not a main class you need it's a main method in your class, the class should have the same name as the file (but without the .java).

public static void main (String[] args) {

inside your class is needed.

But you should have one public class per java file with the same name as the source file without the extension. you can also have private and inner classes in a file but if you want multiple public classes in a package you can create more source files.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic