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 Creating Classes

Public Class Question

Hi Guys,

When I type this 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 character is %s\n",
                    dispenser.mCharacterName);
   }

}

I get this error: Example.Java:8: error: cannot find symbol dispenser.mCharacterName); symbol: Variable mCharacterName variable dispenser of type PezDispenser 1 error

Here is the code I've written for PezDispenser.java:

public class PezDispenser { public String characterName = "Yoda"; }

Ive gone through the video many times and cannot see where my error is. Any help would be appreciated. Thanks.

2 Answers

Geovanie Alvarez
Geovanie Alvarez
21,500 Points

Well the problem is the name of the variable, in the class class PezDispenser you call the variable characterName and then in the System.out.printf you call the variable mCharacterName.

I'll jump in - I had an issue with this also and you have to compare item to item.

For example in PezDispenser.java I named the variable mcharacterName but then in example.java I named it mCharacterName because that's what the instructor had.

Kinda sloppy for a teacher, at 5:31 you'll see the change from characterName (inside the dispenser java) to mCharacterName (as in Example.java).

It's a good lesson to learn, but the video doesn't call it the capital case change out, so you really have to look for it. 30 minutes later.... :)