

class name to run the classpath or the corresponding .class files have been altered. When the JVM is unable to locate the main class, it is usually because you would have entered the wrong. By setting the file path to the system CLASSPATH environment variable.Using the -classpath option at the time of executing the code,.As the name suggests, it is simply a file path where the .class format files can be found in a JDK package or directory. The classpath is the file path where the JRE (Java runtime environment) searches for the classes and other resource files to run the code. We will be exploring in this article how you can easily fix this annoying Java compilation error.īefore we dive into the how and why of it, we need to understand what Classpath is and its role in Java. As serious as it seems, it is not that difficult to fix. class file is and you have CLASSPATH environment variable defined then make sure it include current directory. It is one of the most unpredicted and spontaneous errors in Java, which occurs due to the tendency of JVM to stick with a default classpath, the “main class not found issue” is something that haunts amateurs and professionals alike. If you are getting 'Error: Could not find or load main class XXX', where XXX is the name of your main class while running Java program then do this to solve that error: 1) If you are running Java program right from the directory where.
COULD NOT LOAD MAIN CLASS JAVA INTELLIJ JAR FILE CODE
Why does the “JVM could not find or load the main class” error occur?Īs the name suggests, the ‘could not find or load main class’ error means that the JVM ( Java Virtual Machine) could not locate the main class in your code and throws this runtime error. And we know it has nothing to do with our code. Whether you’re just starting out as a programmer or have some experience under the belt, we’ve all seen this error at least once. If you keep getting this error without any specific reason, you are not alone. Java developers often face the ‘could not find or load main class’ error out of the blue during compilation. Why Organizing Files is important in Java?.Why does the “JVM could not find or load the main class” error occur?.
