Results 1 to 4 of 4
  1. #1
    acp26b is offline Member
    Join Date
    Jul 2008
    Posts
    8
    Rep Power
    0

    Default Problem With Package

    I have a package called Product that has 2 class files, ProductInfo and BinaryFile. Both files are located in the same directory ../Product/ and both files start with "package Product;" I can compile BinaryFile.java just fine. Inside of ProductInfo i want to use the class BinaryFile, however i get a compile error saying:

    Java Code:
    ProductInfo.java:18: cannot find symbol
    symbol : class BinaryFile
    ...
    I did not think an import was needed since the files are in the same directory and in the same package, does any one have any ideas on how to fix the compile error?


    Thanks,
    -Adam

  2. #2
    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

    You mean BinaryFile and ProductInfo are in the same package, but can't access ProductInfo within the BinaryFile class?

  3. #3
    acp26b is offline Member
    Join Date
    Jul 2008
    Posts
    8
    Rep Power
    0

    Default

    Yes both classes are in the same package called Product but it is the other way around. ProductInfo has BinaryFile variables in it. Each product has a preview image so for example inside of ProductInfo there is a variable: BinaryFile previewImage = new BinaryFile('/path/preview.png');

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

    Default

    For the compiler to find a class, the class must be on the classpath. For a class in a package, the classpath must end where the package begins, so that the classpath + package path is the location of the class file.
    For example class X in package pkg located on path: C:\javastuff\pkg\X.class would require a classpath of C:\javastuff.
    If you use javac with -classpath . the . would be a classpath of C:\javastuff\pkg.

Similar Threads

  1. get classes of a certain package
    By ashraf shaban in forum New To Java
    Replies: 4
    Last Post: 07-08-2008, 07:20 PM
  2. JXL Package
    By gaya3 in forum Java Servlet
    Replies: 1
    Last Post: 05-23-2008, 09:03 AM
  3. Package Explorer
    By bilmeze in forum Eclipse
    Replies: 0
    Last Post: 04-04-2008, 08:57 AM
  4. Elements package
    By BlitzA in forum New To Java
    Replies: 0
    Last Post: 12-27-2007, 11:58 PM
  5. Java Package help?
    By Bibendum in forum New To Java
    Replies: 2
    Last Post: 12-12-2007, 04:29 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
  •