• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Error: Could not find or load main class

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Bartender
Posts: 732
10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please do not post screen shots of text. Just copy/paste the text into your post.
 
Ranch Hand
Posts: 165
12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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)
 
Marshal
Posts: 79240
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you ALL,

java -cp . C3 resolved the problem.

Regards,
 
Campbell Ritchie
Marshal
Posts: 79240
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic