Eclipse Error Main
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of
Could Not Find Or Load Main Class Eclipse Error
this site About Us Learn more about Stack Overflow the company Business Learn error could not find or load main class eclipse mars more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question
Error Could Not Find Or Load Main Class Eclipse Luna
x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up error could not find or load main class command prompt Eclipse Error: Could not find or load main class [duplicate] up vote 42 down vote favorite 17 This question already has an answer here: Eclipse “Error: Could not find or load main class” 33 answers Have Googled extensively on this error, but I can't seem to fix the problem. I've written a basic java program in Eclipse Juno, as follows: public class HelloWorld eclipse could not find the main class program will exit { /** * @param args */ public static void main(String[] args) { System.out.println("Hello Eclipse!"); } } After clicking Run, I get: "Error: Could not find or load main class HelloWorld". This error message applies to all my other projects in the same workspace. I've tried switching workspaces but the error still appears. I'm on Windows 7 64-bit. Any help would be appreciated! java eclipse share|improve this question asked May 2 '13 at 9:30 Fezzo 347135 marked as duplicate by Raedwald, Kevin Panko, BobTheBuilder, Paul Beusterien, sethvargo Jan 27 '14 at 17:58 This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question. 1 Is your class definitely not in a package? –Jon Skeet May 2 '13 at 9:35 Have you tryed to select the project and then go to Run -> Run As menu? there you can chose the project type and the main class –Joan May 2 '13 at 9:35 7+ different answers, all of which the submitters claimed worked suggests that this question is "too broad" –Raed
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn
Error Could Not Find Or Load Main Class Eclipse Kepler
more about Stack Overflow the company Business Learn more about hiring developers or how to change classpath in eclipse posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow
Error Could Not Find Or Load Main Class Eclipse Juno
Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Eclipse can't find / load main class up vote http://stackoverflow.com/questions/16334625/eclipse-error-could-not-find-or-load-main-class 24 down vote favorite 9 My Eclipse (Indigo) was running just fine. I created a simple class Hello. It is placed in package cont in the folder ch13. However, when I try to run it from Eclipse I get info from Java Virtual Machine Launcher: Could not find the main class: cont.Hello. I tried to run other classes from this package and they run just fine (that is http://stackoverflow.com/questions/10356854/eclipse-cant-find-load-main-class the classes that existed there before). However any new class I create in this package has these problems. Actually any new class I create in Eclipse runs into this problems. I decided to check how it works from the command line. It seems that the problem still exist - I get same error. I checked the path and it is C:\Program Files\Java\jdk1.7.0_02\bin, which is correct (note the other classes are running from Eclipse just fine). I tried to run with java -cp . Hello and there are some Errors produced starting with java.lang.NoClassDefFoundError: Hello (wrong name: cont/Hello). Code itself is simple: package cont; public class Hello { public static void main(String[] args){ System.out.println("Hello"); } } How can I fix it so that my classes still run under Eclipse? java eclipse share|improve this question edited Feb 8 '13 at 15:59 Kate Gregory 16.1k74378 asked Apr 27 '12 at 19:41 aretai 86641224 Did eclipse generate the .class file for Hello? I think it's usually in bin/ or target/ if you use maven –jeff Apr 27 '12 at 20:12 No maven was used. Tried to find class in the cont folder but there was none. Even if compiled from co
or load main class in Java [Solved] Error: Could not find or load main class HelloWorld comes when you are trying to run your Java program using java command with the main class as HelloWorld but Java is not able to find the class. http://javarevisited.blogspot.com/2015/04/error-could-not-find-or-load-main-class-helloworld-java.html In order to solve this error, you must know how Java find and loads the classes, that's a little bit complex topic for beginners, but we will touch the same base here. For the curious reader, I would http://www.java67.com/2016/09/3-ways-to-solve-eclipse-main-class-not-found-error-java.html suggest reading my post How Classpath works in Java, a must read for a beginner. For now, you just remember that there is an environment variable called CLASSPATH which includes directories where Java looks for all class files could not and if it doesn't find your main class there then it throws "Error: Could not find or load main class XXX", where XXX is the name of your main class. Since many Java programmer is now started programming using Eclipse they face this issue when they first try to run their Java program from command line. In Eclipse, it's easy to compile and run the program because Eclipse takes care of all Classpath setup, but when you could not find run your Java program from command line, CLASSPATH environment variable comes in picture. Personally, I don't like this environment variable and doesn't define in my environment variable, because its confusing and source of so many classpath related issue. Instead, I use -cp or -classpath option with java command to run my program. This way you always know which JARs are included in your classpath. For beginners, another important thing to understand is the difference between PATH and CLASSPATH, you must know that PATH is used locate system executable, commands or .exe, .dll files (in Windows) and .so files (in Linux). It is also used to locate native libraries used by your Java program. While, CLASSPATH is used to locate the class file or JAR files. It's Java class loader who looked into CLASSPATH for loading classes. Coming back to the problem in hand, if you are a beginner in Java, who are able to run the program from Eclipse but getting "Error: Could not find or load main class HelloWorld" when trying to run the same program from the command line then follow the steps given here to solve it. Solving Error: Could not find or load main class HelloWorld Unfortunately beginner's book like Head First Java, which many developers used to learn Java, doesn't teach you how to deal with this kind of errors. You
programmers who gets "Error: Could not find or load main class Main" while running Java program in Eclipse, I was also getting the same problem recently. The "Error: Could not find or load main class" was rendered me puzzled even after my 10+ years of experience with Java errors and exceptions. Whenever I run my Java application either by Run configurations or right click and run as Java program, I get an annoying popup complaining about "could not find or load the main class, the program will exit". I checked, the project was compiling fine, I can see the .class file for the main class in the bin directory of Eclipse, and I can even see the project and output folder added on the classpath of Run configuration, but still I am getting the "could not find main class, program will exit error". I spent good two hours trying everything I could, calling teammates for help (getting an extra pair of eye always helps in this kind of situation), searching on the internet, and lots of trial and error, but the error was persistent. The first clue I got when I debug my Java program. I debug the Java application in Eclipse by right click and choosing "Debug As Java program" and found that it was throwing ClassNotFoundEexception for of a third-party class. It was a kind of break-through after wasting such a long time but still the clue wasn't enough because the class belongs to one of the dependent JAR which was available in classpath but somehow Eclipse was not seeing it. My error was resolved after deleting existing run configuration where User entry was not pointing to default classpath. Just deleting the run configuration and re-creating it by running the class by right click, "Run As Java program" will fix the error. Solution of Error: Could not find or load main class in Eclipse Even though I managed to solve the problem but it was too much a trouble for me and taken a lot of time. I don't want to face the same situation again, especially if I am in