Share this article
Improve this guide
[Fix] Could not find or load main class error in Java
3 min. read
Updated onOctober 4, 2023
updated onOctober 4, 2023
Share this article
Improve this guide
Read our disclosure page to find out how can you help Windows Report sustain the editorial teamRead more
Key notes
Could not find or load main class in a programmingerror, and it usually appears when you write your applications inJava.
Fixing this issue might be hard, especially if you’re new toJava, but hopefully this guide should be able to help you with this problem.
How can I fix could not find or load main class?
1.Check the class name
Note: The most common mistake is when you declare a class name in the wrong format when running it from the compiler.
Also, the correct command to run a.classfilegenerated by theJavacompiler isjavaYou don’t have to provide the.classextension:javaHelloWorld.class.
This is is an obvious solution, but it might work if you’re gettingCould not find or load main classin Eclipse.
2. Check the package name
Note:If your class is included in a package, then to run it you must provide its fully qualified name.
Also, when you create a package, you actually create a folder structure likeC:\Java\classes\packagename\classname.java
After checking your code, theCould not find or load main classJava message should be gone.
3. Remove class references
If you go now toRun Asand selectJavaapplication, Eclipse will write a new configuration for the class you moved. Therefore, it won’t display theerroranymore.
These are some simple guidelines, and they should come in handy if you encounterCould not find or load main classin Eclipse.
Troubleshooting and debugging is an important part of anyJavaapplication you create. This guide provides you solutions for a commonerroryou might meet while running ajavaclass.
If you run it from a Linux terminal and encounter thiserror, the first two solutions will work for you too. Check the class name and the directory from where you run your program.
More about the topics:Programming tools and tips
Vlad Turiceanu
Windows Editor
Passionate about technology,Windows, and everything that has a power button, he spent most of his time developing new skills and learning more about the tech world.
Coming from a solid background in PC building and software development, with a complete expertise in touch-based devices, he is constantly keeping an eye out for the latest and greatest!
User forum
0 messages
Sort by:LatestOldestMost Votes
Comment*
Name*
Email*
Commenting as.Not you?
Save information for future comments
Comment
Δ
Vlad Turiceanu
Windows Editor
Coming from a solid background in PC building and software development, he’s a Windows 11 Privacy & Security expert.