Win a copy of Head First Android this week in the Android 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Rob Spoor
  • Devaka Cooray
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Jj Roberts
  • Al Hobbs
  • Piet Souris

Cannot find symbol error

 
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
reply
    Bookmark Topic Watch Topic
  • New Topic