Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Newcomers » Newcomers » Main class not found(Error message: Could not find or load main class)
Main class not found [message #1799203] Sat, 01 December 2018 19:58 Go to next message
Eclipse UserFriend
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 #1799209 is a reply to message #1799203] Sun, 02 December 2018 10:24 Go to previous messageGo to next message
Eclipse UserFriend
There is no code to run in your main() method.
Re: Main class not found [message #1800509 is a reply to message #1799209] Mon, 31 December 2018 08:47 Go to previous messageGo to next message
Eclipse UserFriend
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 Go to previous messageGo to next message
Eclipse UserFriend
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 Go to previous messageGo to next message
Eclipse UserFriend
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 Go to previous message
Eclipse UserFriend
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!
Previous Topic:Illegal Char <*> error in jar path
Next Topic:Eclipse and Java in Windows XP
Goto Forum:
  


Current Time: Wed Feb 12 08:55:08 GMT 2025

Powered by FUDForum. Page generated in 0.09068 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top