Error: Could not found or load main Class

In Java 8.0 or latter version when you write a program and compile it using command line it compile fine but display an error "Error: Could not found or load main class" when you try to execute this program. When you get the message "Could not find or load main class ...", that means that the first step has failed. The Java command was not able to find the class. And indeed, the "..." in the message will be the fully qualified class name that Java is looking for. if you have specified the class name correctly, the next thing to check is that you have specified the class and  classpath correctly as environment variables.
In this post i will explain to you how to set CLASS and CLASSPATH environment variables. To open environment variables dialogue follow these steps.
  1. Right Click on my computer
  2. Click Advance system setting (system properties dialogue box will open)
  3. From system properties dialogue box click on "Advance" tab.   
  4. Click on "system variables..." button
from system variables box click on "New..." button under user variables.





in variable Name Type "CLASS" and in the value copy and paste bin directory of Java in my case my Java is installed in "C:" drive then value of Class will be "C:\Program Files\Java\jdk1.8.0_181\bin" and click on "OK" button. 



After creating Class variable we need to create another system variable name 'CLASSPATH'. process is same as you did before while creating Class variable. Create on "New..." in Variable name type "CLASSPATH" and value should be "C:\Program Files\Java\jre1.8.0_181\lib\rt.jar;" 



and click on "OK" button. Now compile again your program and execute it. 

Comments

Popular posts from this blog

Free download CCNA Dumps

Download CCNA books and Notes in Free

Excel Spell Number Function