• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Cannot find symbol error

 
Varnam Aayiram
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11021
12
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Varnam Aayiram
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11021
12
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well then you will have to post the actual full error message (instead of the edited version)
 
Varnam Aayiram
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic