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

Jonathan Grieve
MOD
Jonathan Grieve
Treehouse Moderator 91,252 Points

jShell isn't finding the PezDispenser object.

Hi all.

So I'm following the video okay, but I can't seem to get jShell to follow the demo properly. This is what I keep getting in the console.

jshell> .open PezDispenser.java  
|  Error:  
|  illegal start of expression   
|  .open PezDispenser.java 
|  ^                                                                                                

So I guessed again and opened it with

jshell> /open PezDispenser.java            

So I got into the program and found this when I tried to create a new instance.

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

I don't think it matters too much that I can't follow along if I'm understanding it mostly but I thought I'd ask, see if anyone else is having the same trouble.

Craig Dennis
Craig Dennis
Treehouse Teacher

Hey Jonathan!

Can you snapshot your workspace please? I'll try and debug...

/open PezDispenser.java

Should give you access to the type.

Jonathan Grieve
Jonathan Grieve
Treehouse Moderator 91,252 Points

Hi Craig,

Yes sure here's the link :)

http://w.trhou.se/gw6w1rmev1

When I tried it earlier I actually bypassed one of the steps

/open PezDispenser

I tried again and it returned this

jshell> /open PezDispenser                                             
|  File 'PezDispenser' for '/open' is not found.                       

jshell> /open PezDispenser.                                            
|  File 'PezDispenser.' for '/open' is not found.                      

jshell>         

Still some gremlins in there! :)

Craig Dennis
Craig Dennis
Treehouse Teacher

Hmmm...

jshell> /open PezDispenser.java                        

jshell> PezDispenser pd = new PezDispenser("Yoda");    
pd ==> PezDispenser@56ef9176                           

jshell> pd.isEmpty();                                  
$3 ==> false   
Jonathan Grieve
Jonathan Grieve
Treehouse Moderator 91,252 Points

So the snapshot worked when you tried it? Hmmm indeed.

I wonder if there's some sort of network problem my end that's causing it. I had similar problems trying to interact with Telnet in another course.

Or have I got access to a different version of the shell in workspaces?

Craig Dennis
Craig Dennis
Treehouse Teacher

Try typing that exactly...there is literally no difference.

6 Answers

Jonathan Grieve
MOD
Jonathan Grieve
Treehouse Moderator 91,252 Points

Hi Craig,

Okay so I think it's working now, but I'm pretty sure the command at the top here is supposed to do something i.e. list the class and java file associated with the workspace

jshell> /open PezDispenser                                                                                                     
|  File 'PezDispenser' for '/open' is not found.                                                                               

jshell> /open PezDispenser.java                                                                                                

jshell> PezDispenser pd = new PezDispenser("Yoda");                                                                            
pd ==> PezDispenser@56ef9176                                                                                                   

jshell> pd.isEmpty();                                                                                                          
$3 ==> false   

But maybe I misunderstood that. :)

So it looks like I tried it the same way as my OP but I'm still not sure why it didn't work the first time. Anyway thanks for looking into it! :)

Craig Dennis
Craig Dennis
Treehouse Teacher

Yeah that open command is relative file based only.

Melody P
Melody P
801 Points

I'm having similar issues. I noticed that when I type it in the second time, jShell seems to take it in okay, but then when I type in PezDispenser pd = new PezDispenser("Yoda"); jShell doesn't take. jShell just tells me that it cannot find symbol, specifically the symbol: class PezDispenser which doesn't make sense at all.

Jack Cummins
Jack Cummins
17,417 Points

You gave your self a best answer! Is that allowed?

I had the same problem Melody P but when I scanned through my code several more times i found that I had spelled "boolean" as "bolean" at this point in my code ----> public bolean isEmpty(){ once i corrected my spelling error, saved the file, and tried it again everything worked as planned.

It only seems to happen when you have a syntax error somewhere in your PezDispenser.java file :).

i'm having the same issue aswell

heres my workspace https://teamtreehouse.com/workspaces/28115042#