Results 1 to 4 of 4
  1. #1
    nwboy74 is offline Member
    Join Date
    Oct 2008
    Posts
    45
    Rep Power
    0

    Default [SOLVED] Compiling Package Class

    Why can I not compile a single class that uses another class of the same package? I thought that all classes of a package were automatically imported.

    I have a package foo. The directory is named foo. I have two classes: Foobar and Footwo. Footwo uses Foobar. If I'm in the directory foo and do javac Footwo.java, I get errors that it cannot find symbol Foobar. It works if I do javac *.java.

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,513
    Rep Power
    25

    Default

    You need to set the classpath for the compiler so it can find the class. The classpath + the package path is the location of the class file. You have the classpath pointing to the location of the class file instead of to the begining of the package path which would be up one level to where the foo directory is.

  3. #3
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    How did you refer those three package in FooTwo class? Can you show that? Did you try what Norm says?

  4. #4
    nwboy74 is offline Member
    Join Date
    Oct 2008
    Posts
    45
    Rep Power
    0

    Default

    I have to compile from a directory above where the packages are. Then the compiler knows where everything is. Thanks, Norm.

Similar Threads

  1. Compiling a single class
    By ROSOBORONEXPORTCORP in forum New To Java
    Replies: 2
    Last Post: 01-28-2008, 12:27 PM
  2. Compiling a class in a package from cmd
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 12-17-2007, 10:27 AM
  3. Importing / compiling and running with .jar package
    By splinter64uk in forum New To Java
    Replies: 1
    Last Post: 12-05-2007, 02:47 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •