-1

I have written a simple program HelloWorld in java. But when I try to run my java code in command prompt using

java HelloWorld

It returns

Couldn't find or load main class

What should I do?? There's no syntax error in my code!!

  • Do this answer your question ? https://stackoverflow.com/questions/18093928/what-does-could-not-find-or-load-main-class-mean – Pluto May 30 '20 at 11:36

1 Answers1

-1

Adding . to CLASSPATH variable in Environment variables solved my problem!!

Java searches for the classes in the paths mentioned in CLASSPATH variable, if you don't add . there, it won't search for classes in current working directory!!!

Go to Control panel > System and Security > System > Advanced System Settings > Advanced

Click Environment Variables

If CLASSPATH variable is present under User variables , add '.' separated by semicolon. For example if java is installed in C:\Program Files\Java\jdk1.8.0_25\bin , CLASSPATH will be

C:\Program Files\Java\jdk1.8.0_25\bin;.;

Click OK.