• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

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

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Marshal
Posts: 79966
396
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Sheriff
Posts: 22815
132
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ben Graham
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Bartender
Posts: 563
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!
 
Ranch Hand
Posts: 1051
Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
what is the heirarchy of your package
 
Shanky Sohar
Ranch Hand
Posts: 1051
Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Marshal
Posts: 79966
396
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Marshal
Posts: 79966
396
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ok i figure it out sorry about the noob question

welldone.PNG
[Thumbnail for welldone.PNG]
 
Campbell Ritchie
Marshal
Posts: 79966
396
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ubuntu nerd,
Your post was moved to a new topic.
 
You don't know me, but I've been looking all over the world for. Thanks to the help from this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic