Win a copy of Micro Frontends in Action this week in the Server-Side JavaScript and NodeJS forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

K&B book code example question..

 
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • Quote
  • Report post to moderator
Thanks, the below works.

java -classpath . TestShapes

 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic