• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Main class not recognized

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!



 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Space pants. Tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic