wood burning stoves 2.0
The moose likes Java in General and the fly likes the instance variable shapes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "the instance variable shapes" Watch "the instance variable shapes" New topic

the instance variable shapes

mike hew

Joined: Oct 26, 2006
Posts: 27
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

Joined: Aug 16, 2005
Posts: 14993

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.

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
I agree. Here's the link: http://aspose.com/file-tools
subject: the instance variable shapes
It's not a secret anymore!