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
Sinem Süzoglu is currently offline Sinem SüzogluFriend
Messages: 1
Registered: December 2018
Junior Member
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
Tauno Voipio is currently online Tauno VoipioFriend
Messages: 742
Registered: August 2014
Senior Member
There is no code to run in your main() method.


--

Tauno Voipio
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
john 0804 is currently offline john 0804Friend
Messages: 3
Registered: December 2018
Junior Member
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
Zhouping Wei is currently offline Zhouping WeiFriend
Messages: 2
Registered: April 2020
Junior Member
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
Nitin Dahyabhai is currently offline Nitin DahyabhaiFriend
Messages: 4430
Registered: July 2009
Senior Member

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.


_
Nitin Dahyabhai
Eclipse Web Tools Platform
Re: Main class not found [message #1824452 is a reply to message #1824414] Wed, 15 April 2020 13:42 Go to previous message
Zhouping Wei is currently offline Zhouping WeiFriend
Messages: 2
Registered: April 2020
Junior Member
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: Thu Mar 28 19:10:45 GMT 2024

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

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

Back to the top