This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

package problems

 
marilyn murphy
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
  • 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?
 
Kris Nelson
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • 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: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is no SubclassX. SuperclassX is public.
 
Junilu Lacar
Bartender
Pie
Posts: 7316
45
Android Eclipse IDE IntelliJ IDE Java Linux Mac Scala Spring Ubuntu
  • Mark post as helpful
  • send pies
  • 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: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I thought if I put it in the default package I would not have to import it.
 
Junilu Lacar
Bartender
Pie
Posts: 7316
45
Android Eclipse IDE IntelliJ IDE Java Linux Mac Scala Spring Ubuntu
  • Mark post as helpful
  • send pies
  • 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: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there any way to import the default package?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic