Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

No main class found  RSS feed

 
Debbie Thornton
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First I want to THANK YOU ALL so much for all the help!!! Without this site I would have had to quit because no one had the time to help me.     I have tried to work this on my own (as the other problems I have had) and I am getting nowhere.  Please help me.    I cannot figure out why I am getting <no main class found>.  Here is my problem:


  
 
Stefan Evans
Bartender
Posts: 1836
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Debbie,

How are you trying to run it that you get this message?
Are you on the command line or in an IDE?  What commands are you using?
Does the class compile without problems?
You have a main method in this class, but it doesn't seem like it does anything...

 
Debbie Thornton
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HIYA!!!

I am using Netbeans.  I am right clicking on the project and running it from there.  It does compile without problems.
 
Julian West
Ranch Hand
Posts: 91
3
Chrome Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Aside from adding a } at the end, it compiles fine for me.

Your main method doesn't have anything in it, however; it isn't told to do anything.
 
Debbie Thornton
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Should I just break down and redo it?  It compiles for me but will not run.
 
Julian West
Ranch Hand
Posts: 91
3
Chrome Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't know what you mean by "redo" it since this is only a fragment of a program.

You have an abstract class defined--a "template" if you will--with no actual instructions for the program to do anything with it.
 
Stefan Evans
Bartender
Posts: 1836
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Julian already pointed out that your code posted above was missing one '}' which would prevent it from compiling.

Googling for no main class netbeans shows that you aren't the only one to ever come across this problem.

Suggestions I found:
Make sure your project has a main class:

Right click on your Project in the project explorer
Click on properties
Click on Run
Make sure your Main Class is the one you want to be the entry point. (Make sure to use the fully qualified name i.e. mypackage.MyClass)
Click OK.
Run Project

Otherwise, yeah try and "redo" ?

 
Debbie Thornton
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Guys, Will do!!
 
Campbell Ritchie
Marshal
Posts: 55717
163
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why are you using NetBeans at such an early stage in your programming career? Most of us believe that an IDE has so many bells and whistles that you devote more brain cells to learning the IDE than to learning the programming. And, believe me, you need every brain cell you have got for the programming. Unlike Eclipse, NetBeans follows what looks to me like an old‑fashioned convention. You have a class which contains a main method and nothing else. The main method is intended for starting your application and nothing else. (So far I am in agreement with that concept.) The old‑fashioned part is that you call that class mypackage.Main. NetBeans defaults to running the main method in the class called Main, so you get a warning if you don't have a class called Main. It is usually easy enough to fiddle the options so you run the main method in a different class.
You might do well to stop using NetBeans; look here for an alternative suggestion, but ignore the telling off given another user.

You might do well also to create a Shape interface and make your abstract class implement that interface. Beware: all its subclasses will implicitly implement the same interface and all non‑abstract (properly called concrete) subclasses must therefore implement every method in that interface. Possible structure of such an interface:-You will realise that the 90% of that interface which consists of documentation comments (as I told you yesterday) is missing because I only took 30 seconds to write that code. Note that all methods are public and abstract implicitly even though you usually omit those two keywords.
 
Debbie Thornton
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


HI!

I am currently taking online courses to get my Bachelor's degree in IT.  One of my classes is Java Programming and we have to use Netbeans as our IDE.  The program I put up is from a link our instructor gave us.  We had to put it in Netbeans and add more to it, but when I put the information from the link I was getting those error messages.  Programming is like a foreign language to me, I am trying so hard to understand.  I have been spending hours online trying to figure out what I am supposed to do.  When I think I just might have an idea of what is going on, I realize I am wrong.  It is so disheartening.  But, I need to get through this week and next, 7 more programs and hopefully keep my grade.  Thank you and the others for all the help you give.  Sorry for the novel, I just thought I should explain myself.

-Debbie
 
Junilu Lacar
Sheriff
Posts: 11146
160
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Google for Netbeans no main classes found. The links to StackOverflow will lead you to some clues. However, someone pointed out that your main() method contains no code so even if you resolve the NetBeans issue with finding a main class, the program will not actually do anything because you haven't written anything in main().
 
Julian West
Ranch Hand
Posts: 91
3
Chrome Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Debbie Thornton wrote:I am currently taking online courses to get my Bachelor's degree in IT. ...  Programming is like a foreign language to me, I am trying so hard to understand.  I have been spending hours online trying to figure out what I am supposed to do. 


I would suggest, then, to hold your instructor, whom you hired to teach you, to teach you.

Fast forward: let's say you pass this course and check all the other boxes required for your BSIT.  What next?
Freelance?  You won't be equipped.
Get a job?  You'll never pass the initial interview, assuming you got one, or the Oracle certification test that may be required to even get an interview.

Again, I suggest getting what you paid for.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!