Results 1 to 2 of 2
  1. #1
    nttaylor is offline Member
    Join Date
    Dec 2009
    Rep Power

    Default still confused about packages and import

    My question is now more general. OK, so let's say I have two files, and they are both in a directory called "testy":

    1. testy/ looks like this:

    package testy;

    import testy.*;

    public class Testy {
    public static void main(String args[]) {

    2. and testy/ looks like this

    package testy;

    public class Westy {
    public static final String SOME_CONSTANT = "Hello";

    No matter what I do, I can't get to compile. I've tried it with the package declarations and without. I've tried "import testy.*", "import testy.Westy.*" and I've tried leaving out the import statement entirely. I've tried qualifying SOME_CONSTANT as "Westy.SOME_CONSTANT", and I've tried it unqualified. I've tried compiling first, and I've tried leaving it uncompiled, hoping that it will get compiled automatically when I compile

    In every case, I get a compiler error "cannot find symbol: variable SOME_CONSTANT"

    I should point out that all of the above combinations seem equally likely/unlikely to work to me, so I don't really understand what a package declaration is supposed to do, what an import statement is supposed to do, and when you don't have to use either statement because the external file is in the same directory as the one you're compiling.

    Btw, I set my CLASSPATH to include the directory I'm working in, but that didn't change anything. Also I don't understand why I need to worry about CLASSPATH when all of my source files are in the same directory.

    How would you get this to compile?

    My ultimate goal is to split my source code into different files just to keep things organized. Is that possible? Not everything will be a static member so I don't think the "import static" functionality is right for me.

    Grateful for any light in this fog.

  2. #2
    asina12 is offline Member
    Join Date
    Dec 2009
    Rep Power


    Hi nttaylor,


    Try change it to :


Similar Threads

  1. confused about packages and import
    By nttaylor in forum New To Java
    Replies: 7
    Last Post: 12-14-2009, 06:55 AM
  2. import packages
    By gregorio99 in forum New To Java
    Replies: 3
    Last Post: 11-06-2009, 01:43 PM
  3. Very confused Plz help!!
    By ratb0y in forum NetBeans
    Replies: 0
    Last Post: 02-14-2009, 05:34 PM
  4. Replies: 3
    Last Post: 02-12-2008, 12:03 PM
  5. Problems with packages (import statements)
    By ai_2007 in forum Advanced Java
    Replies: 1
    Last Post: 06-29-2007, 11:57 AM

Tags for this Thread

Posting Permissions

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