File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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(
at ShapeTest.main(

Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 15091

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:
subject: the instance variable shapes
It's not a secret anymore!