Java Error: Could not Find or Load Main Class ClassName (Solved)


Java Error

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:

Environment Variable

You search for “Environment”

Click “Edit the System Information Variables”

Click Environment Variables

Environment Variable 2

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;

 

 

Iklan

Satu Tanggapan

  1. makasih referensinya

Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout /  Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout /  Ubah )

Connecting to %s

%d blogger menyukai ini: