Results 1 to 5 of 5

Thread: problem compiling class

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Oct 2002
    Location
    Propped up at a PC near you...
    Posts
    194

    problem compiling class

    I've got a class (ArrayMenu) which uses class (Keyboard) to read which key is pressed to choose from a menu. Keyboard compiles but ArrayMenu has this error (and I don't understand what I've done wrong!) Any one help - please!

    ---------- javac ----------
    ArrayMenu.java:33: cannot resolve symbol
    symbol : variable Keyboard
    location: class ArrayMenu
    choice = Keyboard.readChar();
    ^
    1 error
    Output completed (1 sec consumed) - Normal Termination

    If anyone wants to see the code for the classes I will post them

  2. #2
    Hyperactive Member Kagey's Avatar
    Join Date
    Sep 2000
    Location
    The Wilderness of New Brunswick
    Posts
    294
    remove the package statement at the top of the keyboard.java file. then recompile keyboard.java, and place it in the same directory as ArrayMenu.java.

    Good ol Java Software Solutions by Lewis and Loftus?

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Oct 2002
    Location
    Propped up at a PC near you...
    Posts
    194
    if I remove the package from Keyboard I get 6 errors and it will not compile. ArrayMenu will still not compile. They are both in the same directory

  4. #4
    Hyperactive Member Kagey's Avatar
    Join Date
    Sep 2000
    Location
    The Wilderness of New Brunswick
    Posts
    294
    You must not have the one i was thinking of. sorry dude.

  5. #5
    Addicted Member HairyDave's Avatar
    Join Date
    Aug 2002
    Location
    Er...I can't remember.
    Posts
    196
    Is readChar() a static method?

    I ask because you've used Keyboard.readChar(). This means (I think) that it needs to be static. If its not then I think that the compiler tries to resolve Keyboard as a variable and not a class.

    If its not static you need to declare a variable of typ Keyboard first.

    If its not this problem then have you imported the class - it shouldn't be a problem cos they're in the same directory - but you never know. Are they in the same package?

    I've asked a few questions as I'm not sure whats happening. If you need more help, give us a shout.

    HD

Posting Permissions

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



Click Here to Expand Forum to Full Width