aspose file tools*
The moose likes Beginning Java and the fly likes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark ""cannot find symbol" error" Watch ""cannot find symbol" error" New topic
Author

"cannot find symbol" error

MR Chen
Ranch Hand

Joined: Aug 10, 2007
Posts: 31
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

Joined: Nov 18, 2006
Posts: 689

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

Joined: Aug 10, 2007
Posts: 31
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

Joined: Oct 13, 2005
Posts: 39436
    
  28
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

Joined: Aug 10, 2007
Posts: 31
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

Joined: Oct 13, 2005
Posts: 39436
    
  28
There's a spelling error: MyHand and myHand.
MR Chen
Ranch Hand

Joined: Aug 10, 2007
Posts: 31
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

Joined: May 29, 2008
Posts: 445

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....


Never try to be a hard-worker. Be a smart-worker.
My Blog
Garrett Rowe
Ranch Hand

Joined: Jan 17, 2006
Posts: 1296
Its not the classpath. There is no myHand variable in scope in the CardButton class.


Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them. - Laurence J. Peter
Garrett Rowe
Ranch Hand

Joined: Jan 17, 2006
Posts: 1296
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

Joined: Aug 10, 2007
Posts: 31
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

Joined: Jan 17, 2006
Posts: 1296
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

Joined: Aug 10, 2007
Posts: 31
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: "cannot find symbol" error