I am taking a Udemy class and I am stuck on the first lesson, getting command prompt to write "Hello world" through java. My error is once I have compiled it, and it creates the class file, and I try to run it through "java HelloWorld" it doesn't run. The error is.
Error: Could not find or load main class HelloWorld
And I can't figure it out, Here is a screenshot showing everything I have: https://app.box.com/s/4heybbazxswm4otjazrw
I have looked through my class discussion and no one had the error, and no StackOverflow topics seemed to be the same problem.
Answer
Your CLASSPATH isn't set (or isn't set correctly). From the Java tutorial,
The CLASSPATH variable is one way to tell applications, including the JDK tools, where to look for user classes.
However, you can also specify a CLASSPATH to the java runtime with the -cp
argument (also aliased to -classpath
. A colon separated list of folders, and jar/zip files to search for class files.
That's why
java -cp . HelloWorld
Allowed the JRE to find HelloWorld.class. You could also set CLASSPATH.
No comments:
Post a Comment