• Register
2 votes
24 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.

12 7 7
15,250 points

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.

13 9 6
94,240 points

Related questions

0 votes
1 answer 4 views
4 views
Problem: I am trying to run some java files in a new project. So I make the project, but the files in it and I try to run the main file so my game starts. I get an error that says selection does not contain a main type. I am pretty sure it must work because I ran it a few hours ago at school. How do I get this working? Thank you in advance!
asked Mar 27 ummesalma 22.8k points
0 votes
1 answer 16 views
16 views
Is there anything I need to do?
asked Dec 30, 2020 TeamScript 13.5k points
0 votes
1 answer 37 views
37 views
How can I resolve this error?
asked Dec 28, 2020 TeamScript 13.5k points
0 votes
1 answer 2 views
2 views
Problem: Why I am getting this message? Html helper does not contain a definition for.
asked Apr 1 PkGuy 13.1k points
0 votes
1 answer 10 views
10 views
Problem: java selection does not contain a main type
asked Feb 24 Hira 2.2k points
0 votes
0 answers 4 views
4 views
Problem: I found out that my R.Java is not up-to-date, so it does not contain information about my new resources, so I decided to delete it and thought that eclipse will generate a new one. But that didn't happen and now I don't have R.java. How can I ... caused the problem for me. Cleanup removes R.java ... and for some reason the plugin is not regenerating the file." Hope someone could help me.
asked 6 days ago sasha 16.2k points
1 vote
2 answers 329 views
329 views
Problem: Dear all, Right now I’ve imported a maven project into my eclipse IDE and I changed my java path library to work on java 1.7 Suddenly, eclipse started showing an error but I’ve got no errors in my files there. The error is “java compiler level ... Project Problem (Java Version Mismatch) Please tell me how to resolve this error (I want to have my JRE version as 1.7 only).
asked Mar 22, 2020 Gavin 15.3k points
1 vote
1 answer 29 views
29 views
Problem: Hello guys, I am a novice in the programming world. I&rsquo;ve started learning with the C/C++ language. I&rsquo;ve got a piece of C++ code with two classes. The program is throwing a compile-time error does not name a type I am ... receiveMessage(); vector<Message> *dataMessageList; }; I am looking forward to having a legitimate solution to the problem. Thanks for your kind concern
asked Apr 29, 2020 Gavin 15.3k points
0 votes
1 answer 3 views
3 views
Problem Eclipse Error: Could not find or load the main class I'm on Windows 7 64-bit. Any help would be appreciated!
asked 5 days ago neeraj 9.5k points
0 votes
1 answer 4 views
4 views
Problem: Eclipse Error: Could not find or load the main class I can't seem to fix the problem. I've written a basic java program in Eclipse Juno?
asked 5 days ago neeraj 9.5k points