This problem was giving me a headache for days. I have read some guidance and tips, but with no luck until I read it carefully. When I try to compile the Java program, the compilation is successful. But when I try to run it with command:
java ClassName
An error message as follow appear:
Error: Could not Find or Load Main Class ClassName
Well, you have to do some steps:
1. Set path to your compiler in Environment Variable, e.g.:
C:\Program Files\Java\jdk1.8.0_77\bin;
2. Go to the class folder. E.g.:
cd C:\Users\asus\workspace\tes\src\tes
3. Compile the Java Class in its directory with command:
javac ClassName.java
4. Then you have to go to the upper folder with command:
cd ..
Now you are in the folder:
C:\Users\asus\workspace\tes\src
5. Run the Java Class with folder’s name in front of it:
java tes.objectIntro
That’s all.
To set the Path in Environment Variable is as follow:
You search for “Environment”
Click “Edit the System Information Variables”
Click Environment Variables
Add variable name with:
PATH
and Variable value with your JDK’s folder bin. E.g.:
C:\Program Files\Java\jdk1.8.0_77\bin;
Filed under: Agus Nizami, Java Programming Language | Tagged: Could not Find or Load Main Class |
makasih referensinya