• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Eclipse tells me I have no main class when I clearly do

 
Joao Adriano
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

That is the only class in my program, it is a part of a chat server im trying to make.
When I compile it, eclipse gives me an error "Selection does not contain main type" and it doesn't compile and run.
Can anyone please tell me what I'm doing wrong so I can go on with the actual programming?
Thanks in advance


Non-related:Also, I have read somewhere that using try catch blocks is better than using throws, can anyone explain the difference?
 
Steve Fahlbusch
Bartender
Posts: 605
7
Mac OS X Python
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In Java, just like c and c++ you can not simply make up your own function signature if someone up stream is expecting something else.

As a hint: is pbulic allowed? is void allowed? is main spelled correctly (and the correct capitalization)? does it expect to handle an exception?

 
Joao Adriano
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for fast response!
What do you mean by somone up stream? I don't quite understand, do you mean that the main can't be public or can't return void?
The throws IOException is there because of the IO operations that have to do with the sockets.

I don't understand why you are saying as a hint, does that mean you know what's wrong? If so, please tell me, because I see no reason not to...
I've been programming in java for only 3 days, using the oracle tutorials and other online resources, i didn't take a course or anything, so i just want to understand what I'm doing wrong to improve and not make the same mistake again.

Thanks!
Edit: By the way, what's a function signature?
 
Steve Fahlbusch
Bartender
Posts: 605
7
Mac OS X Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I shall make it a little more obvious.

the guy upstream is the JVM calling your program through a very standard function signature -- if you dont know what that is, do some research.

it looks like you are not using the standard function signature (ie: it is not expcection an exception) and therefore it can not find your function.

 
Joao Adriano
Greenhorn
Posts: 4
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
THANKS FOR THE HINT I found the issue by myself thanks to your hint.\
Also thanks for letting me discover by myself, that was nice.
Will be using these forums more often.
Thank you! is there any way I can give you reputation or something?
 
Steve Fahlbusch
Bartender
Posts: 605
7
Mac OS X Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are welcome --- and you did it prior to me editing my post to make more obious....

Just pass it on --- if you can help in some other post please do so.

contrats on fixing it so fast.......

have a great evening
 
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
Note to bystanders: Steve's hint about the signature of main is a good hint, but the more specific suggestion about exceptions is a red herring -- the exception declaration for a method is not part of the signature, and it's actually OK for a Java main method to declare any exceptions it likes. The missing part of main's declaration here is that it needs to be static.
 
Steve Fahlbusch
Bartender
Posts: 605
7
Mac OS X Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks EFH.

just wanted to ply op with options == good follow up.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic