Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

"Error: Could not find or load the main class..." ERROR..!

 
Prats Shah
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I can compile my "HelloWorld" program successfully but not able to run it. I think a picture can describe more than thousand words. So I am uploading image here as my problem. Please ignore "HelloWorld" Code as I have copied it from your site only and also class name is same as file name . I have changed just classname and filename with "First" instead of "HelloWorld". Here is my query in image.
JAVA Error.JPG
[Thumbnail for JAVA Error.JPG]
 
Saif Asif
Ranch Hand
Posts: 440
Eclipse IDE Hibernate Linux
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Greetings Prats Shah ,

I found your mistake, AFTER compiling the code , instead of typing java First.class , just type java First and it will work fine.
 
Prats Shah
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Prats Shah wrote:I can compile my "HelloWorld" program successfully but not able to run it. I think a picture can describe more than thousand words. So I am uploading image here as my problem. Please ignore "HelloWorld" Code as I have copied it from your site only and also class name is same as file name . I have changed just classname and filename with "First" instead of "HelloWorld". Here is my query in image.
 
Prats Shah
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Aah..! Thank You very much Sir. Thanks a lot..!
 
Saif Asif
Ranch Hand
Posts: 440
Eclipse IDE Hibernate Linux
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your wellcome :-)

Just for the information , the .class extension means that it is the class file containing java byte code which the java compiler created when you issue the javac command .
 
Prats Shah
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes , So if after compilation we want to run the file which is obviously has Bytecodes, so why I can't run with First.class filename? (i.e java First.class)
 
Campbell Ritchie
Sheriff
Pie
Posts: 49742
69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

You can only say, because that is what the java tool is programmed to accept. You are not executing the file, but the class. The class is called First, not First.class.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic