Main class not found [message #1799203] |
Sat, 01 December 2018 19:58  |
Eclipse User |
|
|
|
Hi, I have a problem with my class file.
When I run it I get the error message:
"Could not find or load main class".
Contents of the class file:
public class test {
public static void main(String[] args) {
// TODO Auto-generated method stub
}
}
Thanks in advance.
|
|
|
|
Re: Main class not found [message #1800509 is a reply to message #1799209] |
Mon, 31 December 2018 08:47   |
Eclipse User |
|
|
|
You need to make sure that the class name saved as test.java Also, you need to have some code inside main() method. For example you can use System.out.println("eclipse.org"); inside the main method.
|
|
|
Re: Main class not found [message #1824411 is a reply to message #1800509] |
Wed, 15 April 2020 04:01   |
Eclipse User |
|
|
|
May I know if I could use a name for main class different from the name of the file saving this class? For example:
class GFG
{
public static void main(String[] args) {
// TODO Auto-generated method stub
}
}
And save above class definition to a file called "test.java". I know I can do this in command line but I'm not sure if I can do it using Eclipse
|
|
|
Re: Main class not found [message #1824414 is a reply to message #1824411] |
Wed, 15 April 2020 04:31   |
Eclipse User |
|
|
|
Whether you can or not, it's a bad idea. Classes relate to each other using their type
names, and they're linked at runtime by converting those type names into file paths
relative to the classpath. If you don't match them, you're not going to build anything
more complicated than can fit into a single class.
|
|
|
Re: Main class not found [message #1824452 is a reply to message #1824414] |
Wed, 15 April 2020 13:42  |
Eclipse User |
|
|
|
Thanks for reply, very helpful! No I would never do that!
Why I was asking is just because I found that I'm allowed to do that using command-line (just remove 'public' from main class definition), but not using Eclipse.
So, may I say Eclipse does not allow to do that but command-line allows? Thanks!
|
|
|
Powered by
FUDForum. Page generated in 0.05599 seconds