• 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:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Accessibility Example from Khalid Mughal-getting compilation errors

 
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to work on example 4.8(Pg No:116) but I could'nt compile





Compilation Errors are below


symbol : class SuperClassA
location: class Ekak.MyFavorites.Certification.KhalidMughal.PackageA.SubClassA
class SubClassA extends SuperClassA{
^
C:\Ekak\My Favorites\Certification\KhalidMughal\PackageA\SubClassA.java:5: cannot resolve symbol
symbol : variable superClassVarA
location: class Ekak.MyFavorites.Certification.KhalidMughal.PackageA.SubClassA
superClassVarA = 10;
^
C:\Ekak\My Favorites\Certification\KhalidMughal\PackageA\SubClassA.java:6: cannot resolve symbol
symbol : variable superClassVarA
location: class Ekak.MyFavorites.Certification.KhalidMughal.PackageA.SubClassA
System.out.println("superClassVarA from subclass:"+superClassVarA);
^
3 errors
 
Esther Kak
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can somebody explain why this is not compiling?
 
Ranch Hand
Posts: 621
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi


i think the variable in the super class must be declared as
protected.............

so try the below code








try the above code and
do let me know if it works...............
 
Ranch Hand
Posts: 159
Eclipse IDE C++ Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The syntax of the original code is fine. It compiles fine, no problem there.
No need to add protected or anything (read your K&B).

The reason this does not work is because you compile it wrong. you probably type in the javac instruction yourself, and your classpath is wrong.

please post the javac line.

grtz
mark
 
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use the compilation statement -

>javac -d . SuperClassA.java SubClassA.java

It creates the package directories automatically and compiles the code fine.
 
Esther Kak
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Mohit Jain,
I tried but it did not work with your compilation statement javac -d . SuperClassA.java SubClassA.java

PATH VARIABLE is
C:\j2sdk1.4.2_12\bin

CLASSPATH VARIABLE is
C:\Ekak\My Favorites\Certification\KhalidMughal
Both the following programs are in PackageA under khalidMughal directory.
Program1-SuperClassA.java
Accessibility is:
  • Class name - is default
  • Class variable - public
  • Class method - public

  • Program2 - SubClassA.java
    SubClassA.java extends SuperClassA.java which is in the same package. And defines a simple method to access the superclass variable.

    But the error I get is cannot resolve symbol: SuperClassA
    I have the path variable set to point to the bin dir
    I have my classpath variable set to point to KhalidMughal but not packageA

    Why am I not able to compile the code. Need Help. Can anyone explain?
     
    Esther Kak
    Ranch Hand
    Posts: 51
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Could anybody please reply on this!!! Thanks in Advance
     
    Mark Uppeteer
    Ranch Hand
    Posts: 159
    Eclipse IDE C++ Java
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    hi Esther Kak ,

    I 'managed' to reproduce your error because it always just seem to compile fine for me.
    I get your error, when I execute compilation of the subclass without the superclass being on the same compilation line.

    Position yourself in the folder of your java files.
    javac SubClassA.java gives me:
    ----
    SubClassA.java:2: cannot find symbol
    symbol: class SuperClassA
    class SubClassA extends SuperClassA
    ^
    SubClassA.java:5: cannot find symbol
    symbol : variable superClassVarA
    location: class Ekak.MyFavorites.Certification.KhalidMughal.PackageA.SubClassA
    superClassVarA = 10;
    ^
    SubClassA.java:6: cannot find symbol
    symbol : variable superClassVarA
    location: class Ekak.MyFavorites.Certification.KhalidMughal.PackageA.SubClassA
    System.out.println("superClassVarA from subclass:"+superClassVarA);
    ^
    3 errors

    ----

    but when I execute

    javac SubClassA.java SuperClassA.java

    everything compiles just fine.
    This error occurs because you try to compile a class (SubClassA) that needs a superclass (SuperClassA) but SuperClassA.class doesn't exist yet (or isn't found).
     
    Mark Uppeteer
    Ranch Hand
    Posts: 159
    Eclipse IDE C++ Java
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    now I see its even not the same error. yours is 'resolve', mine is 'find'.
    Guess I didn't manage to reproduce your error after all.

    Fact is that there is nothing wrong with the code. Its configuration.
     
    Esther Kak
    Ranch Hand
    Posts: 51
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Thankyou for taking time to reproduce errors and solve it. Your answer helped me.
     
      Bookmark Topic Watch Topic
    • New Topic