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!!
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!!
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.