File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes K&B book code example question.. Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Reply Bookmark "K&B book code example question.." Watch "K&B book code example question.." New topic
Author

K&B book code example question..

Mike Van
Ranch Hand

Joined: Apr 06, 2006
Posts: 83
This is the example found on page 88, typed in as it was in the book. Here's my code:

class GameShape {
public void displayShape() {
System.out.println("displaying shape");
}
}

class PlayerPiece extends GameShape {
public void movePiece() {
System.out.println("moving game piece");
}
}

class TilePiece extends GameShape {
public void getAdjacent() {
System.out.println("getting adjacent tiles");
}
}

public class TestShapes {

public static void main(String[] args) {
PlayerPiece player = new PlayerPiece();
TilePiece tile = new TilePiece();
doShapes(player);
doShapes(tile);
}

public static void doShapes(GameShape shape) {
shape.displayShape();
}
}

This compiles without an issue, but when executing, I get the following error:
Exception in thread "main" java.lang.NoClassDefFoundError: TestShapes

Any help?


Mike Van
If at first you don't succeed, try, try again. Unless you really suck at it. Then, you might just want to try something else, if you dont' want to be a loser I mean.
J Sato
Ranch Hand

Joined: Mar 30, 2006
Posts: 40
It looks like you need to set your classpath to include the current directory. You might skip ahead to Ch. 10 or search online for additional help.
Mike Van
Ranch Hand

Joined: Apr 06, 2006
Posts: 83
Thanks, the below works.

java -classpath . TestShapes

 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: K&B book code example question..
 
Similar Threads
Compiling multiple source files.
error pg 89 of K&b 5.0 study guide
HELP NEEDED FOR CALLING METHOD OF THE SAME CLASS
Class Casting
i don't get to know why this program cannot be executed?