Association Class


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 7 of 7

Thread: Association Class

  1. #1
    Join Date
    Apr 2004
    Posts
    16

    Association Class

    Hi everyone,

    I have probably what is a very simple question. How do you get an association class to refer to other classes? Example code:

    Code:
    public class Association
    {
    private FirstClass theFirstClass;
    private SecondClass theSecondClass;
    }
    I am getting the error messages:

    cannot resolve symbol: class FirstClass in class Association
    cannot resolve symbol: class SecondClass in class Association

    However, my confusion is increased as my print method in Association seems to recognise the other classes and when actually typing the code (using JBuilder) the lovely suggestion menu appears listing the proper methods available from these other classes:

    Code:
    System.out.println("First Class Attribute:" + theFirstClass.getFirstClassAttribute());
    Any suggestions, as always, most gratefully received. :¬)

  2. #2
    Join Date
    Dec 2002
    Posts
    83
    Are the FirstClass and SecondClass in the same package as Association? If not you might need import statements if you don't have them?
    -- Steven

  3. #3
    Join Date
    Apr 2004
    Posts
    16
    Thanks for the reply, Steven. I think they are in the same package - I have one project with four classes, interfaceClass, firstClass, secondClass, AssociationClass.

    The interfaceClass obviously calls methods in the firstClass and secondClass and if I can get it to work, methods will be called from the associationClass.

    The associationClass will have it's own attributes and will also collect name attributes from the firstClass and secondClass. This is where the problem lies - I think?!

    Relevant association class code goes something like this:

    Code:
    public class Association
    {
    private String assocType;
    private FirstClass theFirstClass;
    
    public Association(String aT, FirstClass fcName)
    {
    assocType = aT;
    theFirstClass = fcName;
    }
    
    public void setAssocType(String aT)
    {
    assocType = aT;
    }
    
    public FirstClass getName()
    {
    return theFirstClass;
    }
    I have not added any extra code to the FirstClass class (which might be the problem?!).

    The relevant association code in the interface class goes something like this (I have not shown the arrays for the other classes that are set within this class as these work & format v similar):

    Code:
    public class Interface
    {
    private Association[] associationList;  //sets association array name
    private int numAssoc;
    
    public Interface()
    {
    associationList = new Association[10];  //array size set
    numAssoc = 0;
    }
    
    public void addAssociation()  //add method
    {
    String firstClassName = Console.readString("?");  //asks the user to input required name
    int fcName = findFC(fcName) 
    //this is the find method to locate the fcName's position in the array-it works (in the other classes anyway)
    associationList[numAssoc] = new Association(aT, fcList[fcName]); 
    //fcList is the array that works containing a name attribute called fcName this is a line of code with an error message - cannot resolve symbol: variable aT in class Interface
    }
    I am ok with the code for adding the new association to the array & incrementing the ID number so have left this out.

    Hopefully this will clarify what I have & what I need to do. If anyone has any suggestions on how to create an association class, I will quite happily scrap my code and start again. I have found a few examples on the net on how to create association classes, but they all seem to do it in the same way as I have. There's obviously something amiss somewhere though!

    Fingers, legs, eyes, etc crossed...

  4. #4
    Join Date
    Feb 2004
    Posts
    541
    just so everyone knows, the problem has been resolved here .

  5. #5
    Join Date
    Apr 2004
    Posts
    16
    Thanks Mike, don't like to multipost but thought I'd try a few well known forums to get different experts' help. I did try a different one first, but got no responses so went a bit mad and posted away!!!

    I know the two forums to return to for advice in future - one of which of course is this one!

  6. #6
    Join Date
    Feb 2004
    Posts
    541
    i know, these are the only two i use. Maybe because you're running on the same engine they just look alike

  7. #7
    Join Date
    Feb 2004
    Posts
    808
    something tells em the fora are related.. but i cant remember what... i think maybe internet.com owns codeguru or soemthing..
    The 6th edict:
    "A thing of reference thing can hold either a null thing or a thing to any thing whose thing is assignment compatible with the thing of the thing" - ArchAngel, www.dictionary.com et al.
    JAR tutorial GridBag tutorial Inherited Shapes Inheritance? String.split(); FTP?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center