Results 1 to 9 of 9
Like Tree1Likes
  • 1 Post By sunde887

Thread: I am getting a cannot find symbol error on this code from Oracle Java tutorial site

  1. #1
    bigsonny is offline Senior Member
    Join Date
    Nov 2010
    Posts
    164
    Rep Power
    4

    Default I am getting a cannot find symbol error on this code from Oracle Java tutorial site

    After I compile this, I get an error saying that day cannot find symbol but this is the code provided by the Java site.

    Java Code:
    public class EnumTest {
    	Day day;
    	
    	public EnumTest(Day day) {
    		this.day = day;
    	}
    	
    	public void tellItLikeItIs() {
    		switch (day) {
    			case MONDAY: System.out.println("Mondays are bad.");
    					     break;
    					
    			case FRIDAY: System.out.println("Fridays are better.");
    					     break;
    					     
    			case SATURDAY:
    			case SUNDAY: System.out.println("Weekends are best.");
    					     break;
    					     
    			default:	 System.out.println("Midweek days are so-so.");
    					     break;
    		}
    	}
    	
    	public static void main(String[] args) {
    		EnumTest firstDay = new EnumTest(Day.MONDAY);
    		firstDay.tellItLikeItIs();
    		EnumTest thirdDay = new EnumTest(Day.WEDNESDAY);
    		thirdDay.tellItLikeItIs();
    		EnumTest fifthDay = new EnumTest(Day.FRIDAY);
    		fifthDay.tellItLikeItIs();
    		EnumTest sixthDay = new EnumTest(Day.SATURDAY);
    		sixthDay.tellItLikeItIs();
    		EnumTest seventhDay = new EnumTest(Day.SUNDAY);
    		seventhDay.tellItLikeItIs();
    		
    		
    	}
    }
    Do you get the same error and do you know if I should worry about it or is there a way to circumvent it?

  2. #2
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,785
    Rep Power
    7

    Default

    Quote Originally Posted by bigsonny View Post
    I get an error saying that day cannot find symbol
    Are we supposed to guess? Copy and paste the full and exact error message.

  3. #3
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    It looks like you are missing the underlying day enum.
    bigsonny likes this.

  4. #4
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,785
    Rep Power
    7

    Default

    Well spotted sunde. From the tutorial:
    Java Code:
    public enum Day {
        SUNDAY, MONDAY, TUESDAY, WEDNESDAY, 
        THURSDAY, FRIDAY, SATURDAY 
    }

  5. #5
    bigsonny is offline Senior Member
    Join Date
    Nov 2010
    Posts
    164
    Rep Power
    4

    Default

    Java Code:
     ----jGRASP exec: javac -g EnumTest.java
    
    EnumTest.java:2: cannot find symbol
    symbol  : class Day
    location: class EnumTest
    	Day day;
    	^
    EnumTest.java:4: cannot find symbol
    symbol  : class Day
    location: class EnumTest
    	public EnumTest(Day day) {
    	                ^
    EnumTest.java:10: cannot find symbol
    symbol  : variable MONDAY
    location: class EnumTest
    			case MONDAY: System.out.println("Mondays are bad.");
    			     ^
    EnumTest.java:13: cannot find symbol
    symbol  : variable FRIDAY
    location: class EnumTest
    			case FRIDAY: System.out.println("Fridays are better.");
    			     ^
    EnumTest.java:16: cannot find symbol
    symbol  : variable SATURDAY
    location: class EnumTest
    			case SATURDAY:
    			     ^
    EnumTest.java:17: cannot find symbol
    symbol  : variable SUNDAY
    location: class EnumTest
    			case SUNDAY: System.out.println("Weekends are best.");
    			     ^
    EnumTest.java:26: cannot find symbol
    symbol  : variable Day
    location: class EnumTest
    		EnumTest firstDay = new EnumTest(Day.MONDAY);
    		                                 ^
    EnumTest.java:28: cannot find symbol
    symbol  : variable Day
    location: class EnumTest
    		EnumTest thirdDay = new EnumTest(Day.WEDNESDAY);
    		                                 ^
    EnumTest.java:30: cannot find symbol
    symbol  : variable Day
    location: class EnumTest
    		EnumTest fifthDay = new EnumTest(Day.FRIDAY);
    		                                 ^
    EnumTest.java:32: cannot find symbol
    symbol  : variable Day
    location: class EnumTest
    		EnumTest sixthDay = new EnumTest(Day.SATURDAY);
    		                                 ^
    EnumTest.java:34: cannot find symbol
    symbol  : variable Day
    location: class EnumTest
    		EnumTest seventhDay = new EnumTest(Day.SUNDAY);
    		                                   ^
    11 errors
    
     ----jGRASP wedge2: exit code for process is 1.
     ----jGRASP: operation complete.

  6. #6
    bigsonny is offline Senior Member
    Join Date
    Nov 2010
    Posts
    164
    Rep Power
    4

    Default

    Quote Originally Posted by sunde887 View Post
    It looks like you are missing the underlying day enum.
    Thanks Sunde887!

  7. #7
    JDScoot is offline Member
    Join Date
    Jun 2011
    Location
    San Diego, CA
    Posts
    24
    Rep Power
    0

    Default

    EDIT: Disregard, I was too slow. You already saw the posts.

    Sunde887 called it. You are missing the Day enum class. Junky posted the missing code just before your last post.
    Last edited by JDScoot; 06-15-2011 at 05:25 AM.

  8. #8
    bigsonny is offline Senior Member
    Join Date
    Nov 2010
    Posts
    164
    Rep Power
    4

    Default

    Yes, thank you to you both Junky and JDScoot as well. I added the code. The way the example on the oracle site is, it is separated so I did not realize that it should go together.

    Thanks!

  9. #9
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,785
    Rep Power
    7

    Default

    "Here is some code that shows you how to use the Day enum defined above:"

    Obviously didn't read the above line.

Similar Threads

  1. Replies: 10
    Last Post: 12-22-2010, 01:12 AM
  2. java:92: cannot find symbol error
    By noviceNewbie in forum AWT / Swing
    Replies: 3
    Last Post: 12-18-2010, 02:46 AM
  3. New Java Video Tutorial Site thebestvideotutorials dot com
    By thebestvideotutorials in forum New To Java
    Replies: 0
    Last Post: 02-15-2009, 11:43 PM
  4. Replies: 9
    Last Post: 10-18-2008, 08:26 PM
  5. [SOLVED] Java Error: Cannot find Symbol...
    By bobleny in forum New To Java
    Replies: 8
    Last Post: 04-15-2008, 06:35 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
  •