• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Beer Song Problem

 
Ken Solanki
Greenhorn
Posts: 1
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 169
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you saving the file as "BeerSong.java" (caution: case sensitive!) ?
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Stuart Goss
Ranch Hand
Posts: 169
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11343
Java Mac Safari
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic