It's not a secret anymore!*
The moose likes Beginning Java and the fly likes Another Error this time while trying to run Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Another Error this time while trying to run "cannot find class"?" Watch "Another Error this time while trying to run "cannot find class"?" New topic
Author

Another Error this time while trying to run "cannot find class"?

Ryan McKay
Greenhorn

Joined: Feb 21, 2011
Posts: 8

Hey everyone again. Thank you so much for all the help you've been to me thus far. I'm working on my third program from the book Head First Java, it compiles ok, but when I try to run it I get this error.


Here is the code in my java file.

Can anyone help point out my failings? I've tried to figure it out on my own, but I'm just stuck. Again. lol thanks for the help in advance!
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

Is there a reason your class isn't declared public?
Ryan McKay
Greenhorn

Joined: Feb 21, 2011
Posts: 8

not really, just how the book had it. I did try it with public class Shuffle1 { as well but it had the same error.
Tom Reilly
Rancher

Joined: Jun 01, 2010
Posts: 618
Your code runs fine when I compile it. Is this all the code in the file? That is, do you have a package statement at the top of the file?
Ryan McKay
Greenhorn

Joined: Feb 21, 2011
Posts: 8

no that's everything I have, no package statement. Out of curiosity, what is a package statement? Sorry for the noob questions.
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

Maybe the current directory is not in the classpath. Try "java -cp . Shuffle1" instead.


[My Blog]
All roads lead to JavaRanch
Death Arte
Greenhorn

Joined: Feb 17, 2011
Posts: 21

@Ryan McKay

Just follow Sir Christophe said..

Here's my command line code which is same as Sir Christophe Verré code.

java -classpath . Shuffle1


Have a nice day Sir!
Ryan McKay
Greenhorn

Joined: Feb 21, 2011
Posts: 8

ah then wait, this must be because I added the classpath and path to my environment variables? Didn't know that would cause these kinds of problems.


Trying it now.

Thanks! That did it! One more thing to remember. lol.
Vijitha Kumara
Bartender

Joined: Mar 24, 2008
Posts: 3832

Ryan McKay wrote:...what is a package statement?

Packaging is a way to separate your code in terms of their functionality. They act as kind of a namespace for your code. It make the code easier to manage and reuse. And it avoids the conflicts which otherwise may occur if you have same function in two different classes with same (or default) package.
I added the classpath...

Don't set the classpath.


SCJP 5 | SCWCD 5
[How to ask questions] [Twitter]
Ryan McKay
Greenhorn

Joined: Feb 21, 2011
Posts: 8

Vijitha Kumara wrote:
I added the classpath...

Don't set the classpath.


So just the path? or should I do neither and just write the path out all the time?
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

The PATH is used to find java/javac so you should leave it instead of having to always type the full path.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Another Error this time while trying to run "cannot find class"?