To avoid this error, you need to specify the absolute (including packages) name of the .class file (just name) which is in the current directory. It means the DemoClass.class file must be inside the directory C:\demo. Once you resolve them and compile your program success fully, an executable file with the same name as your class name is generated in your current folder, with the .class extension. What is the reason behind the error “Could not found or load main class” in java? There are some other reasons that generate the same error, as follows: To avoid or resolve the error, we need to specify the absolute package name or class name. To solve, use the full class name, including package name, in the java command. The CLASSPATH of the application is incorrectly specified. Then you need to execute it using the java command as −, While executing, when JVM does not find a .class file with the specified name then a run time error occurs saying “Could not found or load main class” error as −. Following are the scenarios where this error could occur −. It also occurs when we specify the .class extension at the end of the class name. In the following image, we are not inside the demo folder where the class is located. The error generates because the JVM fails to load the main class or package name. Let's create a program that generates and displays an error on the console. Remember that if the class is inside a package, we must use the full class name, including the package name, in the java command. Could Not Find or Load Main Class in Java. It means, on compiling the following Java program the .class file will be generated inside the C:\demo\com\javatpoint\DemoClass.class. Among these errors, could not find or load main class in Java, is one of them that occurs Subham Mittal has worked in Oracle for 3 years . Solution − The extension .class is not required while executing the program. Mail us on hr@javatpoint.com, to get more information about given services. In order to solve this error, you must know how Java find and loads the classes, that's a little bit complex topic for beginners, but we will touch the same base here. The class has been declared in the wrong package. Solution − In this scenario we have mention the name of the wrong package While executing we need to specify the correct package name in which the .class file exists as −. But some of the most popular and common errors are often faced by programmers who are new in programming. D:\sample>java Example Error: Could not find or load main class Example Caused by: java.lang.ClassNotFoundException: Example Solution To avoid this error, you need to specify the absolute (including packages) name of the .class file (just name) which is in the current directory. Developed by JavaTpoint. Why "this" keyword cannot be used in the main method of java class? JavaTpoint offers too many high quality services. © Copyright 2011-2018 www.javatpoint.com. It is very common to face errors and exceptions in the Java programming language. The main class is a class in which the main() method is defined. But some of the most popular and common errors are often faced by programmers who are new in programming. We see that the above program compiles and runs, successfully. The error also occurs when we don't place the class in the correct folder. Also occurs, when we have done a mistake with the class name argument. It is very common to face errors and exceptions in the Java programming language. Wrong case − You need to specify the name of the class with same case Example.java is different from example.java. Please mail your requirement at hr@javatpoint.com. All rights reserved. We may error could not find or load main class while running the Java class. To avoid the error, do not write .class extension at the end of the class name while using the java command. Let's generate the error that could not find or load main class in the above program. Solution − In this the class name is with wrong case it, it should be decorated. How to fix "Exception in thread main" in java? It occurs when we try to run a program. To generate and display the error, we have misspelled the class name while typing the java command java DemoClas. Wrong package − You might have created the .class file in a package and tried to execute without package name or with wrong package name. In the above program, let's create a package named com.javatpoint. Wrong class name − You might have specified the wrong class name. Inclusion of .class extension − While executing a file there is no need to include the .class extension in your program you just need to specify the name of the class file. C/C++ difference's between "int main()" and "int main(void)". For more java articles ,Click here to Subscribe JavaHungry Solution − In this the class name is wrongly spelt, we need to correct it. How to resolve "Expected BEGIN_OBJECT but was BEGIN_ARRAY" using Gson in Java? Among these errors, could not find or load main class in Java, is one of them that occurs usually. JavaTpoint offers college campus training on Core Java, Advance Java, .Net, Android, Hadoop, PHP, Web Technology and Python. The error indicates that the java command failed to find or load the main class. Java regex program to match parenthesis "(" or, ")". Duration: 1 week to 2 week. The subdirectory path doesn't match the fully qualified name. Once you write a Java program you need to compile it using the javac command, this shows you the compile time errors occurred (if any). Error: Could not find or load main class HelloWorld comes when you are trying to run your Java program using java command with the main class as HelloWorld but Java is not able to find the class. When the error occurs, the JVM shows the following error message on the console: The error is mostly generated when we incorrectly specify the class name at run time of the program. Check if a String is not empty ("") and not null in Java, Difference between using - "standard table of", "Hashed table of", or simply "table of" in SAP ABAP.