Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Java Java Objects Meet Objects Creating Classes

Mark Gormley
Mark Gormley
543 Points

PezDispenser cannot find symbol

I see someone else had this problem but they had a typo in their PezDispenser.java file, I don't. My code:

public class Example {

  public static void main(String[] args) {
    // Your amazing code goes here...
    System.out.println("We are making a new PEZ Dispenser");
    PezDispenser = dispenser = new PezDispenser();
    System.out.printf("The dispenser is %s %n", 
                      dispenser.characterName);

  }

}

and the errors..

Example.java:6: error: cannot find symbol                                                                                                      
    PezDispenser = dispenser = new PezDispenser();                                                                                             
    ^                                                                                                                                          
  symbol:   variable PezDispenser                                                                                                              
  location: class Example                                                                                                                      
Example.java:6: error: cannot find symbol                                                                                                      
    PezDispenser = dispenser = new PezDispenser();                                                                                             
                   ^                                                                                                                           
  symbol:   variable dispenser                                                                                                                 
  location: class Example                                                                                                                      
Example.java:8: error: cannot find symbol                                                                                                      
                      dispenser.characterName);                                                                                                
                      ^                                                                                                                        
  symbol:   variable dispenser                                                                                                                 
  location: class Example

2 Answers

Manish Giri
Manish Giri
16,266 Points

There is a problem in this line - PezDispenser = dispenser = new PezDispenser();.

This part - new PezDispenser() creates an object of type PezDispenser. Ideally you should assign this to a variable of type PezDispenser, so PezDispenser dispenser = new PezDispenser();. Like you would create any regular object - String example = "Hello World";.

So then why do you have the = in the first part here - PezDispenser = dispenser?

Mark Gormley
Mark Gormley
543 Points

Maybe I shouldn't be doing this at 1 in the morning... :/ cheers man

Teacher Russell
Teacher Russell
16,873 Points

I'm studying everyone's questions and answers, and I saw your problem. Made me laugh. About 90% of my problems here came at 1am, or at least after way too many consecutive hours of study. I'd wake up in the morning, see my ridiculous error or question, and then wince as I opened my responses. Luckily, folks here are patient, and don't call you dummy. How's Java going for you now? I just got started.