aspose file tools*
The moose likes Beginning Java and the fly likes Cannot find symbol error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Cannot find symbol error" Watch "Cannot find symbol error" New topic
Author

Cannot find symbol error

Varnam Aayiram
Ranch Hand

Joined: Dec 23, 2008
Posts: 88
I am having some problem with a piece of code I was writing. I have 2 classes, both in the same package. I will name them as class A and class B, neither is a subclass of the other.

I have the following code in class B:



I am getting an error for this line: a.doGet(); doGet is actually a protected method from class A. The error message is as follows:



I am wondering why I am getting this error since I am accessing the protected method doGet( ) via an instance of the A class. Will appreciate if someone can explain to me why I am getting this error. Thanks.
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10376
    
    8

How is your class containing the main method and A packaged? Are they in the same package?
Protected access is allowed only for the same class, classes in the same package or subclasses.

Recommended reading
http://java.sun.com/docs/books/tutorial/java/javaOO/accesscontrol.html


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
Varnam Aayiram
Ranch Hand

Joined: Dec 23, 2008
Posts: 88
Hi...

Thanks for the reply. Main method is in class B. Both class A and class B are in the same package.
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10376
    
    8

Well then you will have to post the actual full error message (instead of the edited version)
Varnam Aayiram
Ranch Hand

Joined: Dec 23, 2008
Posts: 88
Hi..

I think I have figured it out. A very careless mistake on my part. The said method in class A has parameters and I should have passed arguments to it when I am trying to access it via an instance of class A, sadly I had failed to do it and that caused the problem. Thanks.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Cannot find symbol error