The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
February 2002



This page contains an archived post to the Java Answers Forum made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.


Paperlist class vs. paperlist array

Posted by Dan Desch on February 14, 2002 at 8:53 AM

The proximate cause of the error is found by looking at where aPaperList is declared. Evidently the compiler can't see the declaration--is it maybe out of scope?

But it looks like there may be a larger problem. You seem to be mixing up the concepts of an array of objects and the class that encapsulates that array. It is fine (and a good design choice) to create a class called PaperList that contains inside of it a bunch of Paper objects. And if you choose to implement the storage mechanism inside of that class via an array, that also is fine. But that array should be of Papers, not PaperLists. PaperList is the class that contains the array of Papers. Something like this:

class PaperList
private Paper[] paperItem;
... // other stuff to support this class
// plus a constructor to instantiate the
// paperItem array to some size
public void addPaper(Paper aPaper)
paperItem[theNextFreeLocation] = aPaper;
etc. // other code to update next location and
// deal with possible errors

> Hello everyone. Advice on this would be gratefully helpful

> I have created a class called Paper (that includes various parameters such as author, title, date, etc)

> This class consists of multiple set and get methods and has a constructor to intialise the parameters at the beginning. In the main method at the end I have created an instantiation of the Paper class and wish to add this to an array of Paper objects called Paperlist declared in another class.

> In my paperlist array I have created and declared the array and put in a method to add a Paper object to the array as follows :

> public void addPaper(Paper aPaper)
> {
> aPaperList [theNextFreeLocation] = aPaper;
> theNextFreeLocation ++;
> }

> when i call the method to add the instantiation at the end of my my main method with the command

> aPaperList.addPaper(p1);

> I get a compiler error called variable aPaperList cannot resolve symbol. Any ideas?


Sponsored Links

Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us