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 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:

Error:
| 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
seal-mask
.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
seal-mask
.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