Win a copy of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds this week in the Cloud/Virtualization forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

Cannot find symbol error  RSS feed

 
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.
 
Bartender
Posts: 11445
18
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
Bartender
Posts: 11445
18
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.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!