Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Error: Could not find or load main class  RSS feed

 
Mike Bio
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear All

I'm not able to run a simple helloWorld class in via line command. I recieve this error : "Error: Could not find or load main class"

Please see the screenshot:


Java version= JDK 8
Java is set in Path= ;%JAVA_HOME%\bin;
ClassPath is set = ;%JAVA_HOME%\lib\tools.jar;%JAVA_HOME%\lib\dt.jar
%JAVA_HOME%= C:\Program Files\Java\jdk1.8.0_77


Regards,
error.png
[Thumbnail for error.png]
Error
 
Fred Kleinschmidt
Bartender
Posts: 560
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please do not post screen shots of text. Just copy/paste the text into your post.
 
Steffe Wilson
Ranch Hand
Posts: 165
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try this:

java -cp . C3


(-cp tells java which directory to look into for your class file (ie classpath), the dot (.) means current directory)
 
Campbell Ritchie
Marshal
Posts: 55681
162
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
… and at this point we hope you will find out that setting a system CLASSPATH usually does more harm than good. Delete the CLASSPATH and set it with the -cp option whenever you actually need the tools or dt jars. You probably will have to use the -cp option for both java and javac tools.
 
Mike Bio
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you ALL,

java -cp . C3 resolved the problem.

Regards,
 
Campbell Ritchie
Marshal
Posts: 55681
162
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry; I hadn't noticed you are new, so I hope I'm not too late to welcome you here
I still think you are better off deleting that CLASSPATH altogether. There is no need to supply a path to the .jars in the standard JDK to your CLASSPATH. At least not with JDK versions > 12 approx.
But when the problem recurs, you will know what the solution is.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!