Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Eclipse annoyance

 
jeff mutonho
Ranch Hand
Posts: 271
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've created a project in Eclipse , with a few java sources.One of the
classes has and I wish to run this.So I'm doing what I've done many
many times before :
Right click on the class file ---->Select Run ,then a popup appears
I then select "Java Application" under the Configurations list , and
click the "New" button at the bottom , which brings out a tabbed
windows.Under the "Main" tab , my project name correctly appears in
the "Project" field.The "Main Class" field is empty , and a message at
the top of the onfig window saying "Main type not specified".I click
on the Search button in order to get to select the class I want to run
(i.e the main type).A popup appears and the "Matching types" list is
empty.The field to type in the class name is greyed out.
What am I missing?
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The class probably is missing a proper main method?
 
Tim Holloway
Saloon Keeper
Pie
Posts: 18094
48
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The IDE will scan all resources in the project classpath (with an option for expanded scanning inside jars). All classes that contain this exact declaration will be listed in the selection box:

public static void Main(String[] args)

The names and order of the keywords aren't important, but the method signature must match that statement or the class won't be eligible, because it doesn't contain a valid Main method. And, of course "main" isn't acceptable. Java is case-sensitive, so it's got to be "Main". And, unlike C, the argument declaration and return types must be as indicated.
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24208
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Tim Holloway:
And, of course "main" isn't acceptable. Java is case-sensitive, so it's got to be "Main".


Doing some C# lately, Tim? It's the other way 'round: "main()" has to be lower-case.
 
Tim Holloway
Saloon Keeper
Pie
Posts: 18094
48
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oops. Nope, no C#. Just too many main classes named Main.java.

Case-sensitive programming languages.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic