Results 1 to 4 of 4

Thread: enum problem

  1. #1
    guilty is offline Member
    Join Date
    Sep 2010
    Posts
    6
    Rep Power
    0

    Default enum problem

    Hi. I'm new to these forums, and I'll try to behave :)
    Let's get straight to buisness. I have no idea why my code is incorrect:
    Java Code:
    public class Person {
    
        public enum Sex {
    	MALE, FEMALE
        }
    
        private String personalId;
        private Sex sex;
    
        private void setSex() {
    	switch (this.personalId.charAt(0)) {
    	    case '3':
    		this.sex = MALE;
    		return;
    	    case '4':
    		this.sex = FEMALE;
    		return;
    	}
        }
    }
    Netbeans underlines both MALE and FEMALE in method setSex() and gives me an error:

    cannot find symbol
    symbol: variable MALE
    location: class Person


    The same goes with FEMALE.
    Thanks in advance.

    --
    Paul

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,661
    Blog Entries
    7
    Rep Power
    21

    Default

    Type "javac -version" and see if you're running at least version 1.5

    kind regards,

    Jos

  3. #3
    guilty is offline Member
    Join Date
    Sep 2010
    Posts
    6
    Rep Power
    0

    Default

    Java Code:
    C:\Users\Paulius>javac -version
    javac 1.6.0_21
    Yep, it is at least 1.5

    *EDIT* Is it possible that I need to import anything into my file?

    *EDIT* Solved it, I think. Replaced MALE and FEMALE to Sex.MALE and Sex.FEMALE. Silly me :)

    -- Paul
    Last edited by guilty; 09-19-2010 at 11:42 AM.

  4. #4
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,661
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by guilty View Post
    *EDIT* Solved it, I think. Replaced MALE and FEMALE to Sex.MALE and Sex.FEMALE. Silly me :)
    Ah, yes, I missed that one completely; I was focusing on the definition of your enum, not its use. Good you found it yourself.

    kind regards,

    Jos

Similar Threads

  1. Enum inheritance
    By alunina in forum New To Java
    Replies: 1
    Last Post: 02-05-2010, 10:54 AM
  2. enum
    By billq in forum New To Java
    Replies: 3
    Last Post: 01-03-2010, 08:38 PM
  3. Enum example
    By Java Tip in forum java.lang
    Replies: 0
    Last Post: 04-17-2008, 07:34 PM
  4. How to use enum
    By Java Tip in forum java.lang
    Replies: 0
    Last Post: 04-17-2008, 07:34 PM
  5. Enum?
    By vgbhagavan in forum Advanced Java
    Replies: 0
    Last Post: 06-14-2007, 02:02 PM

Posting Permissions

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