Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

"Could not find or load main class" error

 
Nicolette Ender
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there,

I'm taking a beginning Java course and our first assignment was to download the JDK and create a java file in Notepad to run. So far I've done the following:

1. Installed the current JDK
2. Set the PATH system variable to C:\Program Files\Java\jdk1.7.0_13\bin
3. Created the HelloWorld file in Notepad and saved it as a .java file under the C:\Java directory I created
4. Tried to run my program by changing the command prompt directory to C:\Java and then typing "java HelloWorld.java" which returns the attached error. I also tried "javac HelloWorld.java" which just returns the command prompt. I'm not sure the difference between using java vs. javac so if someone could explain that as well that would be helpful

I did notice that there is also a CLASSPATH system variable which is set to .;C:\Program Files (x86)\Java\jre6\lib\ext\QTJava.zip. I'm totally new to this stuff so not sure if that has anything to do with it. I'd really appreciate any help on this so I can get going on the class. Thanks!

Also I'm running in Windows 7.

Thanks!
Nico
CMD Prompt Error.JPG
[Thumbnail for CMD Prompt Error.JPG]
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You missed out step 3.5. Compile the java source file into a class file.
See Compiling and executing the program here
 
Campbell Ritchie
Sheriff
Pie
Posts: 50196
79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch
That classpath variable will have been set when you installed QuickTime. If it starts with .; it should work correctly.
 
fred rosenberger
lowercase baba
Bartender
Posts: 12196
35
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Step 2 worries me...

If it was already set to something and you cleared it out with just what's there, while your java may work, OTHER programs may now be broken...

I can see ADDING that to the beginning of your PATH variable...but wiping out everything that was there with that strikes me as BAD ADVICE.
 
Campbell Ritchie
Sheriff
Pie
Posts: 50196
79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think it is unlikely that she has set the whole PATH like that, Fred. Otherwise she would be reinstalling Windows

It is normal for the javac program to return to the prompt with no messages. Don’t worry: if anything goes wrong it’ll tell you!
 
fred rosenberger
lowercase baba
Bartender
Posts: 12196
35
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
perhaps...but still...I am a developer. I tend to take things quite literally.
 
Junilu Lacar
Bartender
Pie
Posts: 7758
61
Android Eclipse IDE IntelliJ IDE Java Linux Mac Scala Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nicolette Ender wrote:I'm not sure the difference between using java vs. javac so if someone could explain that as well that would be helpful


javac is the command to run the Java Compiler, which takes source files (*.java) and generates bytecode files (*.class) from them.

java is the command to start the Java Virtual Machine (JVM). You only need to give it the name of the class (without the .class extension).


--------

## compile the program
$ javac Hello.java

## run the program
$ java Hello
Hello there!

--------
 
Nicolette Ender
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks all. Up and running!
 
Nicolette Ender
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
fred rosenberger wrote:Step 2 worries me...

If it was already set to something and you cleared it out with just what's there, while your java may work, OTHER programs may now be broken...

I can see ADDING that to the beginning of your PATH variable...but wiping out everything that was there with that strikes me as BAD ADVICE.


Hi Fred,

You were right, I did change this completely by accident. I did a system restore and reinstalled/setup the correct way so should be okay now. Thank you for noticing this!

Nico
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic