aspose file tools*
The moose likes Beginning Java and the fly likes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark ""Could not find or load main class" error" Watch ""Could not find or load main class" error" New topic
Author

"Could not find or load main class" error

Nicolette Ender
Greenhorn

Joined: Feb 13, 2013
Posts: 5
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


[Thumbnail for CMD Prompt Error.JPG]

Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3169
    
  10
You missed out step 3.5. Compile the java source file into a class file.
See Compiling and executing the program here


Joanne
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36508
    
  16
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

Joined: Oct 02, 2003
Posts: 10916
    
  12

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.


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36508
    
  16
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

Joined: Oct 02, 2003
Posts: 10916
    
  12

perhaps...but still...I am a developer. I tend to take things quite literally.
Junilu Lacar
Bartender

Joined: Feb 26, 2001
Posts: 4419
    
    5

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!

--------


Junilu - [How to Ask Questions] [How to Answer Questions]
Nicolette Ender
Greenhorn

Joined: Feb 13, 2013
Posts: 5
Thanks all. Up and running!
Nicolette Ender
Greenhorn

Joined: Feb 13, 2013
Posts: 5
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
 
Consider Paul's rocket mass heater.
 
subject: "Could not find or load main class" error
 
Similar Threads
Cannot run program from another directory other than c:\Sun\SDK\jdk\bin
'javac' is not recognized as an internal or external command,
Java Beginner
problems installing java
Compiling in the cmd prompt