• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

package problems

 
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Every time I think I understand this, I find again that I don't.

SuperclassX.java and SubclassY.java are both in C:\Java. No problem compiling SuperclassX.java, however SubclassY.java won't compile.
C:\Java\SubclassY.java:4: cannot resolve symbol
symbol : class SuperclassX
location: class packageY.SubclassY
public class SubclassY extends SuperclassX
^
I have directory C:\Java\packageY and my classpath includes it. I've tried C:\Java\javac SubclassY.java
I've tried C:\Java\packageY\javac SubclassY.java

Well, I won't tell you what all I tried, but nothing works. What am I doing wrong?
 
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My guess is that SubclassX (EDITED, I meant this to be SuperclassX, sorry) has default (or package) visibility and cannot be accessed by other classes outside the SAME default package.
------------------
WebNelly.com
Java/XML Web Development
Check it out! http://www.webnelly.com
[This message has been edited by Kris Nelson (edited November 09, 2001).]
 
marilyn murphy
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There is no SubclassX. SuperclassX is public.
 
Sheriff
Posts: 17644
300
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The problem is that you declare SubclassY as belonging to packageY while SuperclassX does not have a package declaration making it belong to the DEFAULT package.
These are your options :

  • put the same package declaration in SuperclassX to make it belong in packageY as well
  • remove the package declaration in SubclassY to make it belong to the default package as well.

  • If you choose the first option, you may have to compile with the -sourcepath and -d options (see the help by typing just 'javac') if your source files are in C:\Java. To avoid the hassle of having to deal with the options, just put your source files in a directory with the same name as the package they belong to.
    A third option: you declare the classes to belong to different packages (say packageX for SuperclassX). You must then include the statement
    import packageX.*;
    in SubclassY.java so that it can "see" SuperclassX.
    HTH
    ------------------
    Junilu Lacar
    Sun Certified Programmer for the Java� 2 Platform
    [This message has been edited by JUNILU LACAR (edited November 09, 2001).]
 
marilyn murphy
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I thought if I put it in the default package I would not have to import it.
 
Junilu Lacar
Sheriff
Posts: 17644
300
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by marilyn murphy:
I thought if I put it in the default package I would not have to import it.


If you put it in the same package, you won't have to import it.

------------------
Junilu Lacar
Sun Certified Programmer for the Java� 2 Platform
 
marilyn murphy
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is there any way to import the default package?
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic