aspose file tools*
The moose likes Beginning Java and the fly likes Beer Song Problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Beer Song Problem" Watch "Beer Song Problem" New topic
Author

Beer Song Problem

Ken Solanki
Greenhorn

Joined: Dec 30, 2005
Posts: 1
I have tried to see what the problem is but I cannot identify it. Please help

Ken

The Error message I get when I try to run is,

Exception in thread "main" java.lang.NoClassDefFoundError: BeerSong/java

The Program compiles ok but just cannot run.

The text is as follows:

public class BeerSong {

public static void main (String[] args) {

int beerNum = 99;

String word = "bottles";


while (beerNum > 0) {

if (beerNum == 1) {

word = "bottle"; // singular, as in ONE bottle.

}

System.out.println(beerNum + " " + word + " of beer on the wall");
System.out.println(beerNum + " " + " of beer.");
System.out.println(" Take one down.");
System.out.println(" Pass it around.");

beerNum = beerNum - 1;


if (beerNum > 0) {

System.out.println(beerNum + " " + word +" of beer on the wall");
} else {
System.out.println(beerNum + "No more bottles of beer on the wall");

} // end else
} // end while loop
} // end main method
} // end class
Stuart Goss
Ranch Hand

Joined: Mar 21, 2001
Posts: 169
Are you saving the file as "BeerSong.java" (caution: case sensitive!) ?
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

Hi Ken,

Welcome to JavaRanch!

When you compile the program, you need to include the .java extension. But when you run the program, do not type any extension.

javac BeerSong.java
java BeerSong


"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
Stuart Goss
Ranch Hand

Joined: Mar 21, 2001
Posts: 169
That's probably it.

I copied the code,
saved it as "BeerSong.java",
compiled it with "javac BeerSong.java"
and ran it with "java BeerSong":

no problem.

Good Luck,
Stuart
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

Originally posted by Stuart Goss:
That's probably it...

If you try to run typing the .java extension (java BeerSong.java), then you will get the same error described above. The tip-off in this situation is the "/java" at the end of "Exception in thread "main" java.lang.NoClassDefFoundError: BeerSong/java".
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Beer Song Problem