• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

the instance variable shapes

 
mike hew
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
CREATE the instance variable shapes, an array of Shape objects, with myFile.getCountOfRecords() elements

which I try'd: Shape[] shape = shapes;
but I get the error:


Exception in thread "main" java.lang.ClassCastException: Circle
at ShapeTest.loadShapesArray(ShapeTest.java:121)
at ShapeTest.main(ShapeTest.java:24)

 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15216
36
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In this line:

shape[index] = (Shape) new Circle(Integer.parseInt(myFields[c_xCoordinateField]),

you are casting a Circle to a Shape. You get the error because class Circle is not a subclass of class Shape.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic