File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Could not find main class 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 main class" Watch "Could not find main class" New topic
Author

Could not find main class

Darcy John
Greenhorn

Joined: Dec 13, 2009
Posts: 3
After compiling my simple little program with no errors when it comes to run it using Java i get the error could not find the main class.

C:\Head First Java\Code\Chapter 1>java Shuffle1.class
Exception in thread "main" java.lang.NoClassDefFoundError: Shuffle1/class
Caused by: java.lang.ClassNotFoundException: Shuffle1.class
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
Could not find the main class: Shuffle1.class. Program will exit.

this happened with the last little program as well but when I cleared the CLASS PATH it worked fine. This is an annoying little program.



any other information you need feel free to ask

thanks for any help you may be able to provide
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Clear the classpath again?

If the class you've written is in the default package, and your classpath is set incorrectly, it's not going to run.

Edit: Wow, I wasn't payng attention. Sorry.
Darcy John
Greenhorn

Joined: Dec 13, 2009
Posts: 3
The class path at present holds no value.
Vijitha Kumara
Bartender

Joined: Mar 24, 2008
Posts: 3829

Darcy John wrote:The class path at present holds no value.

Since your class in default package if you run from the directory where the class resides use "java -cp . <classname>" command.


SCJP 5 | SCWCD 5
[How to ask questions] [Twitter]
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41798
    
  62
The way to execute a class is not to use "java Shuffle1.class", but "java Shuffle1".


Ping & DNS - my free Android networking tools app
Darcy John
Greenhorn

Joined: Dec 13, 2009
Posts: 3
Ahh right thanks alot ulf
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Could not find main class