• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

on the subject of packaging

 
colton peterson
Ranch Hand
Posts: 97
Linux Python VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you have a package with two classes and one class wants to use the other class do you have to import the package even though they are in the same package?
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24212
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nope. They'll both have the same "package x.y.z;" line, of course.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No you don't need to explicitly import it.
 
colton peterson
Ranch Hand
Posts: 97
Linux Python VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
is there any kind of declaration you have to do so that classes in the same package can "see" each other, because I can not compile my class because it can't find my other classes. I have checked the classpath.

Let me guess. The next thing you guys will ask is "Can you post the code" so here it is


and here is the error messages

[ March 30, 2008: Message edited by: colton peterson ]
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ref: JLS - 7 Packages...
A package consists of a number of compilation units (�7.3). A compilation unit automatically has access to all types declared in its package and also automatically imports all of the public types declared in the predefined package java.lang.
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by colton peterson:
... I have checked the classpath...

What is your classpath set to? Which directory are you compiling from?

ShapeIcon and SyncPoint are both declared to be in the package com.googlepages.kpcode.LynxVsRabbit, right?
[ March 30, 2008: Message edited by: marc weber ]
 
colton peterson
Ranch Hand
Posts: 97
Linux Python VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
actually I explicitly set it when I compiled I think I still have it somewhere in my command prompt . . .

 
colton peterson
Ranch Hand
Posts: 97
Linux Python VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks. I got some more errors but they are different than before. Back to debugging!
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In Java, classes are identified by their qualified names. Because ShapeIcon is in the package com.googlepages.kpcode.LynxVsRabbit, its qualified name is com.googlepages.kpcode.LynxVsRabbit.ShapeIcon, and this is found in the directory C:\Documents and Settings\Kolten\Desktop\lynx vs rabbits\class. Use that as your classpath, and it should work.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic