• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

"cannot find symbol" error

 
MR Chen
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Let's say that I have 3 classes - A, B, and C.

A creates an instance of B and an instance of C.

Now B wants to get some info out of C. How do I do that?

I tried having B call a getInfo() method in C, but got a "cannot find symbol" error.

Does A have to get the info and store it temporarily for B to pick up? That seems very clunky and inelegant.

Any help is greatly appreciated.
 
Kaydell Leavitt
Ranch Hand
Posts: 689
Eclipse IDE Firefox Browser Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Will you post your code. And, remember to use code tags so that the code will retain its format and be readable.
 
MR Chen
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sure, here's the first class ("class A" in my original post):



And the second class ("B"):



And the final class ("C"):


So, when I compile CardButton, I get this error:


Thanks for having a look
 
Campbell Ritchie
Sheriff
Posts: 48652
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Where do you declare myHand in the CardButton class? It is a non-existent variable, so the compiler can't compile it. You have to declare myHand somewhere.
 
MR Chen
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oops! Didn't change that name everywhere. The first line in the VideoPoker class' StartGame() method should be:

CardHand MyHand = new CardHand();

However, even when I do that, I still get the same error:



How do I pull information from the CardHand object (myHand) into the CardButton objects (cardButton0, cardButton1...)?
 
Campbell Ritchie
Sheriff
Posts: 48652
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There's a spelling error: MyHand and myHand.
 
MR Chen
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK, that happened when I was typing it into my response.

There's no spelling error in the actual code (all instances of "p1CardHand" are actually "myHand" in the code).

And I still get the same error.

I have the feeling that it's not a spelling error that's getting me here. I think I'm missing a basic concept. I just wish I knew what.
 
Rajkumar balakrishnan
Ranch Hand
Posts: 445
Android Eclipse IDE Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please do read this link....And probably it may be a classpath problem..Go check your classpath and try to compile by include your classpath....
 
Garrett Rowe
Ranch Hand
Posts: 1296
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Its not the classpath. There is no myHand variable in scope in the CardButton class.
 
Garrett Rowe
Ranch Hand
Posts: 1296
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One way to handle this type of relationship is for the CardButton to know nothing about the CardHand class. The VideoPoker class already has a reference to each CardButton, it should be responsible for telling the CardButton class what card it represents and telling the CardButton to display itself.
 
MR Chen
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I checked the classpath, and believe it looks fine. And I was able to get another program to compile, so I think that just reinforces the idea that the classpath is not the problem.

I tried deleting all the old class files and re-compiling (as suggested in that thread), and still the same error.

Any other ideas? This is really frustrating.
 
Garrett Rowe
Ranch Hand
Posts: 1296
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by MR Chen:
I checked the classpath, and believe it looks fine. And I was able to get another program to compile, so I think that just reinforces the idea that the classpath is not the problem.

I tried deleting all the old class files and re-compiling (as suggested in that thread), and still the same error.

Any other ideas? This is really frustrating.

Let me reiterate. It's not your classpath, its your program. There is no myHand variable in scope in the CardButton class.
 
MR Chen
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Garrett - sorry I missed your reply when I was writing mine.


One way to handle this type of relationship is for the CardButton to know nothing about the CardHand class. The VideoPoker class already has a reference to each CardButton, it should be responsible for telling the CardButton class what card it represents and telling the CardButton to display itself.


So then, fundamentally, would you say that my problem is one of mindset? Rather than expecting these objects to be able to reach out willy-nilly to get the data they want, I need to have a traffic manager who anticipates who needs what data, and shuttles it around accordingly.

In my example, the VideoPoker class would take that traffic manager role, as it has knowledge of the other two classes (i.e. they are both "in scope" for it). If a CardButton object is going to need to know about a Card within a CardHand object, then the VideoPoker class needs to Get that info from the CardHand object, and Set it into the CardButton object, yes?

Also, you mentioned that

One way to handle this type of relationship is for the CardButton to know nothing about the CardHand class.


What would be another way to handle this type of relationship?

Thanks so much for your help.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic