Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Java Java Objects Harnessing the Power of Objects Abstraction at Play

Cannot find symbol error in jshell

So when I try to run the command PezDispenser pd = new PezDispenser("Yoda"); in jshell, I get the following error message:

| cannot find symbol
| symbol: class PezDispenser
| PezDispenser pd = new PezDispenser("Yoda");
| ^----------^

As far as I can tell I am doing things the same way as the instructor, but apparently not so I was hoping for some input as to what I might be doing wrong.

So far this is what I have coded:

class PezDispenser { public static final int MAX_PEZ = 12; final private String characterName; private int pezCount;

public PezDispenser(String characterName) { this.characterName = characterName; pezCount = 0; } public void fill() { pezCount = MAX_PEZ; }

public boolean isEmpty() { return pezCount == 0; }

public String getCharacterName() { return characterName; }


2 Answers

Florian Tönjes
.a{fill-rule:evenodd;}techdegree seal-36
Florian Tönjes
Full Stack JavaScript Techdegree Graduate 50,856 Points

Hi Michael,

your code looks fine to me. Did you run the following line before trying to create a PezDispenser?

/open PezDispenser.java

Otherwise it won't work.

Kind Regards, Florian

marios armakolas
marios armakolas
2,147 Points

i also have the same problem.

i run the /open PezDispenser.java but i receive the following message

jshell> /open PezDispenser.java
| Error:
| cannot assign a value to final variable characterName
| this.characterName = characterName;
| ^----------------^

Florian Tönjes
.a{fill-rule:evenodd;}techdegree seal-36
Florian Tönjes
Full Stack JavaScript Techdegree Graduate 50,856 Points

Hi Marios,

I cannot reproduce your error. Perhaps it will help to delete the workspace and create a new one. You can do this under the "workspace" link in the navigation bar.

Kind Regards, Florian