Noclass Error Hello World
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 this site About Us Learn more about Stack could not find main class eclipse Overflow the company Business Learn more about hiring developers or posting ads with us Stack error could not find or load main class helloworld in cmd Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community
Could Not Find Or Load Main Class Java Cmd
of 6.2 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up “Could not find or load main class” Error while running java program using cmd prompt up vote
Could Not Find Or Load Main Class Jar
18 down vote favorite 11 I am running a simple "HelloWorld" Program. I get this error in the command prompt: Could not find or load main class HelloWorld. I have set the CLASSPATH and PATH variable in the system. In the cmd prompt, I am running from the directory where I have saved HelloWorld program. I can see the class name and the file name are same and also .class file error: could not find or load main class linux created in the same directory. What else could be the problem? My sample program looks like this: package org.tij.exercises; public class HelloWorld { public static void main(String[] args) { // TODO Auto-generated method stub System.out.println("Hello World!!"); } } java cmd classpath environment-variables share|improve this question edited Dec 10 '15 at 22:35 kenorb 22k8154127 asked May 7 '14 at 23:27 user241702 181115 How are you running the program ? –Kakarot May 7 '14 at 23:29 Please provide the operating system you are using and command line that you are using to attempt to run the program. –ErstwhileIII May 7 '14 at 23:49 File HelloWorld.class must be in the directory org/tij/exercises. Then you can run the example with java -cp . org.tij.exercises.HelloWorld –Andrea Luciano May 7 '14 at 23:58 I am running on windows 7 using jdk 1.8.. –user241702 May 8 '14 at 0:03 Command prompt looks like this... C:\Users\xyz\Documents\Java\javastudy\src\org\tij\exercises>javac HelloWorld.java C:\Users\xyz\Documents\Java\javastudy\src\org\tij\exercises>java HelloWorld Error: Could not find or load main class HelloWorld –user241702 May 8 '14 at 0:08 | show 2 more comments 9 Answers 9 active oldest votes up vote 25 down vote When the Main class is inside a package then you need to run it as follows : java
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 more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs
Error: Could Not Find Or Load Main Class Netbeans
Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community error: could not find or load main class scala of 6.2 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 javac file not found hello.world.HelloWorld up vote 4 down vote favorite I am trying to run this project called "hello user". I am new to Java, so wrote a simple program that takes your name, and displays "Hello ". while Running it, I get the following error: run: http://stackoverflow.com/questions/23530173/could-not-find-or-load-main-class-error-while-running-java-program-using-cmd-p Error: Could not find or load main class hello.world.HelloWorld Java Result: 1 BUILD SUCCESSFUL (total time: 0 seconds) But when I run file HelloWorld.java, it does it fine I am doing this on Netbeans IDE 7.2 java share|improve this question edited Oct 7 '12 at 1:06 Trevor Senior 9,44273658 asked Oct 7 '12 at 0:56 Anonymous Person 3464825 Where you do get that Error at, are you trying to run it at the command line or inside of netbeans? To run your program at the command line you http://stackoverflow.com/questions/12765201/error-could-not-find-or-load-main-class-hello-world-helloworld have to specify the package name in front of the class name. For example to run yours you would type java hello.worl.HelloWorld to run it. –Logan Oct 7 '12 at 1:04 Rather than the coding error, it could be related to IDE. Since the "Run File" runs okay, but 'Run Project" does not, I believe you have something to set up in IDE itself. Right click the project, and select "Set is as Main" or something similar, now run the project. I am just giving it a guess, may not help you. But it worth a shot.Otherwise, paste your whole code. –Jimmy Oct 7 '12 at 1:26 add a comment| 5 Answers 5 active oldest votes up vote 1 down vote accepted Rather than the coding error, it could be related to IDE. Since the "Run File" runs okay, but 'Run Project" does not, I believe you have something to set up in IDE itself. Right click the project, and select "Set is as Main", now run the project. I am just giving it a guess, may not help you. But it worth a shot.If it does not help, please paste your code too. share|improve this answer answered Oct 7 '12 at 1:30 Jimmy 1,470919 thanks guys.. really appreciate –Anonymous Person Oct 8 '12 at 19:08 If any of the answer helped you to solve your problem, please accept that answer by clicking the Check next to question. –Jimmy Oct 8 '12 at 19:29 add a comment| up vote 1 down vote You need to run the .class file cont
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. In order to http://javarevisited.blogspot.com/2015/04/error-could-not-find-or-load-main-class-helloworld-java.html 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 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 and if it doesn't find your could not 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 run your Java program from command line, CLASSPATH could not find 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 need to build this skill by doing active development. In order to understand the problem little bette