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 Head First Java 2nd Ed | Chpt 1 | BeerSong Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Head First Java 2nd Ed | Chpt 1 | BeerSong" Watch "Head First Java 2nd Ed | Chpt 1 | BeerSong" New topic
Author

Head First Java 2nd Ed | Chpt 1 | BeerSong

Aaron Jackson
Greenhorn

Joined: Jun 03, 2005
Posts: 9
Greetings,

This is my first post at the JavaRanch and I sure hope I'ma handlin this right cowboy. Anyway, the problim is sich...

I typed in the code listed on page 14 of Head First Java 2nd Ed. (chapter 1, BeerSong) and after a few syntax error corrections was able to succesffuly compile BeerSong.java into BeerSong.class, however when I attempt to run the code I am met with the following error:

C:\>java C:\SRC\BeerSong
Exception in thread "main" java.lang.NoClassDefFoundError: C:\SRC\BeerSong

I am using Windows XP with Java 5.0
I have set PATH to include "bin"
My source files are obviously stored in the "SRC" directory

This is the first java code I have attempted and have only dabbled in VB6 a couple of years ago. I sure was hoping to get a little further along before I hit a wall. Any help you can give will be greeted with a great big Thank You.

---
By the way, I am using Windows Notepad to type my code using tabs to indent the code. If you can recommend an editor that is equally as simple as Notepad, but that adds automatic indentation of some kind that would be great. Head First Java recommends not using an IDE at this point and I think that is sensible so I am not looking for a lot of functionality here, just indentation. Thanks Again!
[ June 03, 2005: Message edited by: Aaron Jackson ]
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
This sounds like a CLASSPATH issue. At this point, you shouldn't have the CLASSPATH set to anything (unless you've installed something that set it automagically). To find out, you should type:

C:\SRC> echo %CLASSPATH%

and let us know what the output is. I'll be glad to help you from there.

Layne


Java API Documentation
The Java Tutorial
Aaron Jackson
Greenhorn

Joined: Jun 03, 2005
Posts: 9
Are responses here at the JavaRanch always this quick? Ok, after following your instructions I recieve the following output:

C:\SRC>echo %CLASSPATH%
"C:\WINDOWS\system32\QTJava.zip"

I have been exploring JavaRanch in the meantime. I'll just keep looking around until I hear from you again...or until tommorow, whichever comes first.

Thank you!
John Dell'Oso
Ranch Hand

Joined: Apr 08, 2004
Posts: 130
Aaron,

Assuming that you have compiled BeerSong.java into the same src directory (i.e. there should be a file in c:\src called BeerSong.class), first change your current directory to c:\src and then try running BeerSong from there.

Run the following two commands from the command prompt:

1) c:\> cd src
2) c:\src> java BeerSong

Regards,
JD
Aaron Jackson
Greenhorn

Joined: Jun 03, 2005
Posts: 9
Yeah, I thought about trying that, unfortunately I get the same result:

C:\SRC>java BeerSong
Exception in thread "main" java.lang.NoClassDefFoundError: BeerSong

I don't really know much about (or understand) the "CLASSPATH" discussion yet. I tried setting it to C:\SRC\ which is where my BeerSong.class file resides, but this had no effect. I'm not sure where it needs to be pointing. I read the article found here, but I don't think I followed it completely and I am still unable to run my .class files (I have compiled another one in the meantime which gives me a similar error).
Megs Maquito
Ranch Hand

Joined: May 18, 2005
Posts: 84
could you post your code please. Thanks


I'm a Hood Ornament
Nigel Browne
Ranch Hand

Joined: May 15, 2001
Posts: 673
Have you tried to run the program using:
By adding the -cp flag followed by a . you set the current directory onto you classpath
Nigel Browne
Ranch Hand

Joined: May 15, 2001
Posts: 673
Originally posted by Nigel Browne:
Have you tried to run the program using:
By adding the -cp flag followed by a . you set the current directory onto you classpath
Aaron Jackson
Greenhorn

Joined: Jun 03, 2005
Posts: 9
Originally posted by Nigel Browne:

By adding the -cp flag followed by a . you set the current directory onto you classpath<hr></blockquote>[/QB]


C:\SRC\java -cp . BeerSong //this was successful!

Thank you very much! Can you tell me how I can avoid typing this in each time or this the preffered method?
Jeremy Clark
Greenhorn

Joined: May 03, 2005
Posts: 3
Originally posted by Aaron Jackson:

By adding the -cp flag followed by a . you set the current directory onto you classpath<hr></blockquote>[/QB]<hr></blockquote>

C:\SRC\java -cp . BeerSong //this was successful!

Thank you very much! Can you tell me how I can avoid typing this in each time or this the preffered method?[/QB]


Try following the directions in the "How To Set The Classpath" article you linked, but instead of modifying the Classpath variable, just delete it.

To address your editor question: I'm working through Head First Java myself and have picked up jEdit. It's an excellent programmer's editor written in Java.

-J
Aaron Jackson
Greenhorn

Joined: Jun 03, 2005
Posts: 9
Originally posted by Jeremy Clark:
Try following the directions in the "How To Set The Classpath" article you linked, but instead of modifying the Classpath variable, just delete it.

To address your editor question: I'm working through Head First Java myself and have picked up jEdit...


That did it Jeremy, Thank You!!

I downloaded jEdit last night and it does look impressive, but it has so many options I'm not sure where to begin. Do you use any of the available plug-ins or are you using it "out-of-the-box" as it were?
Jeremy Clark
Greenhorn

Joined: May 03, 2005
Posts: 3
Originally posted by Aaron Jackson:
That did it Jeremy, Thank You!!

I downloaded jEdit last night and it does look impressive, but it has so many options I'm not sure where to begin. Do you use any of the available plug-ins or are you using it "out-of-the-box" as it were?


I started using it out of the box, but I have since added Buffer Tabs, Console, and FTP.

-J
Aaron Jackson
Greenhorn

Joined: Jun 03, 2005
Posts: 9
Sounds good Jeremy. Thanks to everyone for the input! I'm off to become a world class Java coder. Well, I'm on to chapter 2 anyway.
Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9044
    
  10
I'd suggest putting the "C:\WINDOWS\system32\QTJava.zip" back at the end of your classpath because that is probably where QuickTime looks when you try to run it.
[ June 04, 2005: Message edited by: Marilyn de Queiroz ]

JavaBeginnersFaq
"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
Aaron Jackson
Greenhorn

Joined: Jun 03, 2005
Posts: 9
I hadn't thought of that! Won't that put me back at sqare one? Should I have to change "CLASSPATH" each time I decide to write some code...or at least each time I decide to run it? That doesn't seem verry intuitive.
Megs Maquito
Ranch Hand

Joined: May 18, 2005
Posts: 84
I also had classpath problem. I simply added the directory where I will be writing java classes.
Aaron Jackson
Greenhorn

Joined: Jun 03, 2005
Posts: 9
Originally posted by Megs Maquito:
I also had classpath problem. I simply added the directory where I will be writing java classes.


Ok, I thought I had done that at one time, but apparently not. I now have the CLASSPATH set to C:\WINDOWS\system32\QTJava.zip;C:\SRC\ and everything is working as it should!

Thanks to everyone for following through on this! I have participated in a lot of technology forums and this is the most polite group I have ever had the privelege to participate with. I was researching Java for weeks before I jumped in, and I never found this site (I don't know why). This is a very beginner friendly site. Head First Java was worth the price just to find JavaRanch...and the book is great too!
 
 
subject: Head First Java 2nd Ed | Chpt 1 | BeerSong