• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem with the main class!

 
eshu khare
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In the following code,I am missing something.It is generating the error 'main class can not be found.....',can you please help me with this.The code is as following.


Thanks & Regards
Eshu
 
Ankit Garg
Sheriff
Posts: 9528
33
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your program is just fine. You have not set the classpath environment variable. If a classpath environment variable doesn't exists create one and add . to it.
If classpath environment variable exists set ;. at it's end...
Check This for Assistence
 
Vikas Kapoor
Ranch Hand
Posts: 1374
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ooops you missed public keyword.
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Vishal Pandya:
Ooops you missed public keyword.


i do not think ,this is the problem .please can you explain me?
 
Adinath Shirsath
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you need to have one public class in order to run it
that public class will contain main method
 
Vikas Kapoor
Ranch Hand
Posts: 1374
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by seetharaman venkatasamy:
i do not think ,this is the problem .please can you explain me?
Ok. Then tell me the actual problem?
 
Rob Spoor
Sheriff
Pie
Posts: 20659
64
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Adinath Shirsath:
you need to have one public class in order to run it
that public class will contain main method

The class doesn't need to be public at all.
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Adinath Shirsath:
you need to have one public class in order to run it
that public class will contain main method



not required .correct me if i am wrong
 
Adinath Shirsath
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by seetharaman venkatasamy:



not required .correct me if i am wrong


yes it is not required to compile the file
but it need to run class file
without that how can jvm acess main method from clas file???
 
Adinath Shirsath
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Adinath Shirsath:


yes it is not required to compile the file
but it need to run class file
without that how can jvm acess main method from clas file???




ok i am sorry
it seems it not need to class be public
 
eshu khare
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No problem I stated was exactly the same but now I got my error,in actual I wrongly named the compilation unit that is instead of Books I named it Book.Now I have got it done correctly.In last would like to thanks to all for kind consideration and help.

Thanks & Regards
Eshu
 
Ankit Garg
Sheriff
Posts: 9528
33
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Adinath Shirsath:


yes it is not required to compile the file
but it need to run class file
without that how can jvm acess main method from clas file???


O come on. I can show you a ton of examples where the class containing the main method is not public. You need to make the class containing the main method public to make the class accessible from outside the package.

I have even tried to execute main method from a non-public class from the containing package and it works......
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic