File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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
Author

the instance variable shapes

mike hew
Greenhorn

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: 14074
    
  16

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 7 API documentation
Scala Notes - My blog about Scala
 
Don't get me started about those stupid light bulbs.
 
subject: the instance variable shapes
 
Similar Threads
enhanced for loop hangup?
Null Pointer Exception
Where am I getting this from?
constructor
lost n confussed