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

His works, mine doesn't. I think it's exactly the same, so what's wrong?

His Pez Dispenser code is working and mine it's, but as I look at my workspace and his on the video, they seem exactly the same, except his works and mine gets errors.

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.getCharacterName());
    }
}
public class PezDispender {
  private String mCharacterName = "Yoda";

  public String getCharacterName(){
    return mCharacterName;
  }
} 

"

I keep getting errors and I'm worried about continuing on in the lesson until I know why

sorry I'm also new to entering code in comments

I totally comprehend what he's teaching in the lesson, which is making my errors that much more frustrating, knowing I"m going to punch myself when I realize what's what.

Loving the lessons by the way.

3 Answers

Oh boy. So much needless punching. It's like I did some crazy slight of hand trick, but to myself. Not sure how that went unnoticed.

many thanks

Craig Dennis
Craig Dennis
Treehouse Teacher

Happens to all of us, man. Keep at it!

The half full glass says, that now you know where to look with those errors.

I'm gonna mark your answer as best, cuz I love the slight of hand trick analogy.

Craig Dennis
STAFF
Craig Dennis
Treehouse Teacher

Look closely at your class name where you define it. See anything funky?

Let me know if that hint does it ;)

I knew I was going to punch myself, especially since I spelled checked SO MANY OTHER WORDS!

Now that's resolved but now I seem to be getting a "hey this is private" error

javac Example.java && java Example
./PezDispenser.java:1: error: class PezDispener is public, should be declared in a file named PezDispener.java
public class PezDispener {
^
Example.java:6: error: cannot access PezDispenser
PezDispenser dispenser = new PezDispenser();
^
bad source file: ./PezDispenser.java
file does not contain class PezDispenser
Please remove or make sure it appears in the correct subdirectory of the sourcepath.

Again, things seemed to be smooth sailing up to this point. Many thanks for your time

Craig Dennis
Craig Dennis
Treehouse Teacher

Prepare for more punching ;)

Anything look wrong with the file name?

/PezDispenser.java

:)