Hi guys I need some help I have just installed the eclipse IDE and am trying to run the Hello World program but it is showing this
@suubi7 Oh sorry about this! kindly checkout out the tutorial on this https://www.baeldung.com/java-could-not-find-load-main-class. link.
@suubi7 which steps have you done to create a class in your eclipse?
i went to the file right clicked and then went to new then selected class and eclipse did the rest
Sorry about that , hope one of these helps…
Try running it using the command line (without using Eclipse), here is how to compile and run java programs using cmd or eclipse Do you get the same error?
You can check the Classpath setup in Eclipse too, hope Techwalla helps
you seem to have created the class manually , and you seem to miss the Package declaration.
The easy way is to use Ecclipse to create your class
- Start Eclipse.
- Create a new Java Project:
- File->New->Project .
- Select " Java " in the category list.
- Select " Java Project " in the project list. Click " Next ".
- Enter a project name into the Project name field, for example, "
Hello World Project".
- Click " Finish "–It will ask you if you want the Java perspective to open. (You do.)
- Create a new Java class:
- Click the " Create a Java Class " button in the toolbar. (This is the icon below " Run " and " Window " with a tooltip that says “New Java Class.”)
- Enter "
class name" into the Name field.
- Click the checkbox indicating that you would like Eclipse to create a "
public static void main(String args)" method.
- Click " Finish ".
thank you i have done this but problem still persistent
The error seems to be caused by the default JRE( Java RunTime Environment) that is failing to provide the class libraries and other resources that your Java program needs to run .
Hint: Remove the default JRE present in your workspace and set it to JRE Version corresponding to your installed Java version
Follow these steps and share your experience
- Right click on your project
- Go to Build Path–> Configure Build Path .
- Go to Library. Under Module Path click JRE System Library and remove the current JRE System Library. The Remove Button is on the right side labelled "Remove " .
- Then click “Add Library” which is just at the right side
- Then Choose “JRE System Library”. Then click Next.
- Choose “Execution Environment” instead of “Workspace default JRE”
- Then in the drop down menu, choose the JRE version that corresponds to your installed java --version.
- Then click finish
- Then click “Apply and Close” Button
- Run the program again
how do you know the JRE that corresponds to the installed java.
Which OS(operating system) are you running on your pc
Windows 10 But i have figured out the problem its now working I have found the JRE thank you for the help
@suubi7 Are you able to run your program
yess Its now running I am even running others and they are giving out put
@suubi7 Its a good practice to share what you have done to resolve the challenge so that others who may face a similar scenario in future can be guided prior to the instance.
@kdaud shared the solution on this link
okay will definitely do
You must ensure that you add the location of your .class file to your classpath. So, if its in the current folder, add . to your classpath. Note that the Windows classpath separator is a semi-colon, i.e. a ;.
Also, if your source code name is HelloWorld.java, your compiled code will be HelloWorld.class.
You will get that error if you call it using:
Instead, use this: