• Register
2 votes
32 views

Problem:

Let me thanks to all Kodlogs users first. I found this website very helpful over the internet. I found all the users and their behavior and solutions very helpful.

Anyway, I am trying to learn java and I write my very first java program. Unfortunately, my code is not running. Every time I try to run my program it throws back an error: java editor does not contain a main type

I am attaching my code snippet below:

public class HelloWorld{
   public static void main(String[] args){
       System.out.println("Hello World!");
   }
}

Note: I am using eclipse java as my IDE. Don’t know is it the problem of my coding or the IDE.
Any legitimate solution is appreciated.

15.3k points
reopened by

Please log in or register to answer this question.

1 Answer

2 votes
 
Best answer

Solution:

This problem can occur for a coup;e of reasons. The first one is if your code doesn't have the main function, and the other one is if your source folder isn’t identified as the source folder by the IDE.

However, you have the main function in your program. So, we can amid the first option. The obvious reason is your IDE couldn’t identify the source folder.

Let’s fix it by doing:

  1. Right-click on the project folder -> Properties
  2. Choose 'Java Build Path'
  3. Click on 'Sources' tab on the top
  4. Click on 'Add Folder' on the right panel
  5. Select your folders and apply

Now you are all set to go. Compile your program and run.
Thanks.

94.3k points
selected by