It's not a secret anymore!*
The moose likes Beginning Java and the fly likes selection does not contain a main type...Hello world program Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "selection does not contain a main type...Hello world program" Watch "selection does not contain a main type...Hello world program" New topic
Author

selection does not contain a main type...Hello world program

Ben Graham
Greenhorn

Joined: Jun 07, 2011
Posts: 3
Hi guys... my first post.

I have eclips and I flowed the eclips hello world tutorial. The coad looks like;



The tutorial said "To right-click on your class in the Package Explorer and select Run As > Java Application."
When I select Run As it pops up with a separate box and when I click Java Application the Run Box at the bottem is gray and I cant click it.
If I click the green run arrow in the tool box at the top and select Java Application it pops up with the "selection does not contain a main type" error message.

Any help with this would be grate.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39878
    
  28
Welcome to the Ranch

No, you haven't followed the tutorial properly. That print statement must be inside a method. You have missed the stage where you click main method as you create your class. You need to insert
before the print statement, and this after itThe spaces are intentional.

You have also spelt the method wrongly. It should read
Ben Graham
Greenhorn

Joined: Jun 07, 2011
Posts: 3
Here is a print screen of the tutorial.


I tryed adding what you said to add, fixed the spelling and it sill is giveing me the same error message.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19762
    
  20

That method should be inside the class; between the first { and the first }. And then you must still fix the typos: System, not systen or system (Java is case sensitive), and println with an L, not printin.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Ben Graham
Greenhorn

Joined: Jun 07, 2011
Posts: 3
Rob Spoor wrote:That method should be inside the class; between the first { and the first }. And then you must still fix the typos: System, not systen or system (Java is case sensitive), and println with an L, not printin.

Im not sure if I understand this (I am a complete noob) but the code looks like this now.



now im getting a "Project root [in hello world] dose not exist" message.
Greg Brannon
Bartender

Joined: Oct 24, 2010
Posts: 563
A Java statement is the smallest unit that is a complete instruction. Java statements must end with a semi-colon:


Put your code in code tags: highlight the code, select the "Code" button in the editor menu area.

When you get error messages, post them exactly as they occur, cut and paste.

Good luck!


Always learning Java, currently using Eclipse on Fedora.
Linux user#: 501795
Shanky Sohar
Ranch Hand

Joined: Mar 17, 2010
Posts: 1051

what is the heirarchy of your package


SCJP6.0,My blog Ranchers from Delhi
Shanky Sohar
Ranch Hand

Joined: Mar 17, 2010
Posts: 1051

and welcome to javaRanch..

From error message it seems to me that your project is wrong..Can we get the screenshot of the eclipse where you have created this file
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39878
    
  28
Open a terminal. If you are on Windows, use start->programs->accessories->command prompt.
Enter the following commands:
mkdir java [or some other suitable name for a folder]
cd java
java -version
javac -version

If you get something sensible from the -version commands, then you have your JDK installation set up correctly.
Use a text editor and open a file called helloWorld.java (it should really be HelloWorld, but I am copying your code), and save it in the "java" folder you just created. Copy and paste all the text from Eclipse into that file.
If the first line starts "package", then put // at the very beginning of that line, because you don't want a package name at this stage.
Save the text file again.
Go back to your command line, and write dir. You should now see the name of the file you created. Make sure it hasn't got .txt added to its name. If that happened, go back to Notepad, and "save as" "helloWorld.java", the difference being that you add "" to the name.
Back to the command line. Enter the following commands:
javac helloWorld.java
java helloWorld
You will find similar instructions here. If anything goes wrong, there is a "common problems" link at the bottom of that page.

This problem shows why we recommend beginners don't try an IDE. You can get confused about the IDE's instructions, and miss out the Java™. You need to be very careful about the spellings. You will notice the correct spellings for your code in this thread, only they are in parts, so you can copy and paste earlier postings and put your class together from those. If you are copying from this website, use the "view plain" link, otherwise you get line numbers added, which you don't want.

If you are not using Windows, look for our FAQ.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39878
    
  28
Greg Brannon wrote: . . . Java statements must end with a semi-colon:

Apart from that correction, the code you quoted is correct. You need to add that ; as GB has shown you
Put your code in code tags: highlight the code, select the "Code" button in the editor menu area. . . .
I have done that to make life easier for you.

Make that one correction, adding the ; and your code will compile and run. There are a few bits of spacing which are not ideal, but the compiler will ignore that.
J perez
Greenhorn

Joined: Oct 16, 2011
Posts: 2
ok i figure it out sorry about the noob question



[Thumbnail for welldone.PNG]

Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39878
    
  28
ubuntu nerd,
Your post was moved to a new topic.
 
Don't get me started about those stupid light bulbs.
 
subject: selection does not contain a main type...Hello world program