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![](https://ecs-static.teamtreehouse.com/assets/views/marketing/shared/community-banner-white-47072046c51352fe6a69f5e691ff5700b28bb11d45197d7bdf066d9ea3f72d0c.webp)
![Ben Kaufman](https://secure.gravatar.com/avatar/cb7dcda14236fa9a673e8b28c8447a8a?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Ben Kaufman
6,813 PointsCan't seem to create a new instance of the PezDispenser Object using jshell and I can't spot why
Ok so The best thing I can do I link each section of my code
Example.java
public class Example {
public static void main(String[] args) {
// Your amazing code goes here...
PezDispenser dispenser = new PezDispenser("Qui Jon");
System.out.printf("the dispenser is a %s \n",
dispenser.getCharacterName());
String before = dispenser.swapHead("Darth Vader\n");
System.out.printf("The swapped out head is %s the new head is %s\n",
before,
dispenser.getCharacterName());
}
}
PezDispenser.java
class PezDispenser {
private String characterName;
public final int MAX_PEZ = 12;
public String getCharacterName(){
return this.characterName;
}
public PezDispenser( String name) {
this.characterName = name;
}
public String swapHead( String characterName){
String originalCharacterName = this.characterName;
this.characterName = characterName;
return originalCharacterName;
}
}
Then I compiled it
javac PezDispenser.java
Then open jshell
then I entered the following
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 know why this isn't working and It is preventing me from progressing. I understand the concepts and what each piece is supposed to do, something is wonky though
3 Answers
![adrian miranda](https://secure.gravatar.com/avatar/fcdf6c268e35635a453e38444b69c7f8?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
adrian miranda
13,561 Pointsjshell does not know anything about the fact that you previously compiled the classes. As a result, when you attempt to create a PezDispenser, it gives you an error. Jshell hasn't heard of a PezDispenser.
If you want to be able to create a PezDispenser in jshell, you first need to tell jshell about it. The easiest way would be to use the mouse to select and copy the contents of the file, then paste them into jshell.
![Tim Barbarino](https://secure.gravatar.com/avatar/ca4cc6d241de87732431f809498085e4?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Tim Barbarino
5,449 PointsAdrian is right in saying that jshell doesn't know anything about any programs that you ran previously.
I believe the issue is that you did not open the file in jshell.
You can do this with the /open command.
Ie, /open PezDispenser.java
Then, you should encounter no problems with what you were trying.
![Mark Harrigan](https://uploads.teamtreehouse.com/production/profile-photos/10760531/micro_May_Profile_Pic_2020.jpg)
Mark Harrigan
7,686 PointsHi all,
I don't have an answer, but I am experiencing something similar to the above. In jshell I have put in the command /open PezDispenser.java and it seems to open with no errors, then when I try to input PezDispenser pd = new PezDispenser("Yoda"); I receive the same error as listed above?
I also noticed that Craig enters another line: /open PezDispenser.PezDispenser.class PezDispenser.java What does this accomplish? I attempted to input this to try something different but I receive: File 'PezDispenser.PezDispenser.class PezDispenser.java' for '/open' is not found.
I did read the comment about simply copying and pasting the code into jshell, but Craig doesn't show this process so I am confused as to why this would be suggested?
Any clarity would be appreciated.