Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Association Classes

 
Emma Lucy
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:

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:

Any suggestions, as always, most gratefully received. :�)
 
Tobias Hess
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are all three classes in the same file? If not, in the same directory/package?
What you've written should work just fine. There's a problem with finding the other classes.
 
Emma Lucy
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The classes are all part of the same project stored in the same place.
I have found similar examples of association code that all seem to use the same code I've applied, but there's obviously something crucial missing cos it just doesn't work!
Can anyone suggest another way of creating an association class that has its own attributes and collects the name attribute of two other classes then stores this information in an array? I'll very happily try anything suggested!!!
 
John Smith
Ranch Hand
Posts: 2937
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
cannot resolve symbol: class FirstClass in class Association
cannot resolve symbol: class SecondClass in class Association

Are all three classes in the same package? Did you try to compile FirstClass and SecondClass before you compile Association?
 
Stefan Wagner
Ranch Hand
Posts: 1923
Linux Postgres Database Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you familar with the 'private' keyword?
 
Emma Lucy
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the replies. Yes the project compiled beautifully before I added the association class and all 4 classes are stored in the same directory, with the classpath set up correctly.
I am familiar with the private keyword, I have already tried to make them public in the declarations of the association class, but the same error message appears. All the methods in association class are public, and the firstClass & secondClass are declared as public classes.
Anymore ideas pls? If someone could suggest another way that an association class is created - a way that works! - would be great.
 
Tobias Hess
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
cannot resolve symbol: class FirstClass in class Association
Could it be that the compiler somehow think FirstClass is a inner class in Association? Please, post the complete error messages including the correspondending lines of your code where that error occurs.
Just to be sure that it's not an issue with packages and files, try to copy the two classes in the same file as the association class. Another thing to try before jumping out of the window is 'make clean' or it's equivalent in your ide.
Tobias
 
Emma Lucy
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks again for the reply. Patient is the First class, Appointment is the Association class, one patient has many appointments.
String s is properly declared in the appointment class and pName is declared in appointment class (thePatient = pName), patientList is the array for patients that works set up in the interface class. appointmentList is the array properly set up in the interface class with appNum being the size of the aray.
Relevant code and error messages below:

"Appointment.java": cannot resolve symbol: class Patient in class Appointment at line 7, column 13

"Appointment.java": cannot resolve symbol: class Patient in class Appointment at line 12, column 68

"Appointment.java": cannot resolve symbol: class Patient in class Appointment at line 44, column 12

"SurgeryInterface.java": cannot resolve symbol: variable s in class SurgeryInterface at line 261, column 51
Any ideas pls?
 
Tobias Hess
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Open the file Appointment.java, add a new first line to that file like this:
class Patient { }
What error messages are you getting now?
The only problem with your code is that the compiler can't find the Patient class for some reason.
Another thing to try out is to comment out every package statement in both files (you said they are both in the same directory).
Tobias
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic