r/javahelp • • May 12 '19

I can't execute java code after compiling

Hi there
Is there anyone that have come across this error:
Error:Could not find or load main class
Caused by: java.lang.ClassNotFoundException
I deleted and added the classpath reinstalled java but nothing has helped
The code compiles but it doesn't run

0 Upvotes

22 comments sorted by

View all comments

Show parent comments

1

u/TalxTrapi May 12 '19

Why did this work

3

u/shagieIsMe Extreme Brewer May 12 '19

Apparently the class path was getting overriden somewhere to not include . by default. If you have a JAVA_CLASSPATH environment variable set, this could do it. By specifying it on the command line, it ignores the environment variable.

1

u/TalxTrapi May 12 '19

Is there anyway i can that the class path to don't get overriden

1

u/morhp Professional Developer May 13 '19

JAVA_CLASSPATH isn't set by default so you must have made a setting that changes it. Try echo %JAVA_CLASSPATH% in the cmd window to see how it is set. Maybe that helps.

1

u/plsdontattackmeok Nooblet Brewer Aug 29 '19

How about for MacOS?

1

u/morhp Professional Developer Aug 29 '19

I believe that should also apply to osx, but I don't use them, so no guarantee.

Edit: It's probably echo $JAVA_CLASSPATH on mac and linux

1

u/plsdontattackmeok Nooblet Brewer Aug 29 '19

Ahhh ok thanks. I also have same problem by OP too

but when I try echo $JAVA_CLASSPATH, I got blank instead

→ More replies (0)