aspose file tools*
The moose likes Beginning Java and the fly likes Problem with the main class! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Problem with the main class!" Watch "Problem with the main class!" New topic
Author

Problem with the main class!

eshu khare
Ranch Hand

Joined: Aug 01, 2008
Posts: 44
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


Thanks & Regards
Eshu Khare
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9305
    
  17

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


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Vikas Kapoor
Ranch Hand

Joined: Aug 16, 2007
Posts: 1374
Ooops you missed public keyword.
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

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

Joined: Dec 04, 2007
Posts: 35
you need to have one public class in order to run it
that public class will contain main method
Vikas Kapoor
Ranch Hand

Joined: Aug 16, 2007
Posts: 1374
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

Joined: Oct 27, 2005
Posts: 19720
    
  20

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.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

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

Joined: Dec 04, 2007
Posts: 35
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

Joined: Dec 04, 2007
Posts: 35
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

Joined: Aug 01, 2008
Posts: 44
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

Joined: Aug 03, 2008
Posts: 9305
    
  17

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......
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem with the main class!