• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

K&B book code example question..

 
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 83
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks, the below works.

java -classpath . TestShapes

 
You know it is dark times when the trees riot. I think this tiny ad is their leader:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic