selection does not contain a main type...Hello world program
Ben Graham
Greenhorn
Joined: Jun 07, 2011
Posts: 3
posted
0
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: 32694
4
posted
0
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
posted
0
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.
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.
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: 530
posted
0
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!
Learning Java using Eclipse on OpenSUSE 11.2
Linux user#: 501795
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: 32694
4
posted
0
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.
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.