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

When trying to compile my PezDispenser code I always get this error which seems to point out a "." as the problem?

I'm fairly certain that my code should work, tried to match video exactly, but I keep getting an error upon compiling-

Example.java:8: error: cannot find symbol                                                        
                      dispenser.characterName);                                                  
                               ^                                                                 
  symbol:   variable characterName                                                               
  location: variable dispenser of type PezDispenser

Really not sure what the problem is as my code looks fine to me.

public class Example {

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

}

Here's the PezDispenser.java code incase-

class PezDispenser {
  String chraracterName = "Zarya";
}

Any help would be greatly appreciated.

1 Answer

Jason Anders
MOD
Jason Anders
Treehouse Moderator 145,858 Points

Hey Brent,

It's actually just a small spelling error in the variable name that is causing the problem.

class PezDispenser {
  String chraracterName = "Zarya";
}

You have an extra 'r' in characterName.

Keep Coding! :dizzy:

Oh my gosh, I thought I double checked everything for that. Thanks, Jason!