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 (Retired) Meet Objects Privacy and Methods

Lucas Alcoba
Lucas Alcoba
1,407 Points

cannot find symbol

i have the code word by word as it is on the video but it keeps giving me this error: example.java:6:error: cannot find symbol

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 character is %s\n",

my guess is that it can't find the Pezdispenser class we made

Post your PezDispenser.java file

Carlos Federico Puebla Larregle
Carlos Federico Puebla Larregle
21,074 Points

I don't know what's in your "PezDispenser.java" file but if you did changed the access modifier of the "mCharacterName" variable to "private" you're going to have to access to it from a "getter" method like this:

    public String getCharacterName() {
        return mCharacterName;

And then you'll have to change in the Example file to actually call that method, so instead of "dispenser.mCharacterName" it would be like this: "dispenser.getCharacterName()" (of course if you named the method "getCharacterName()")

I hope that helps a little bit.