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

Saad Hamid
Saad Hamid
3,150 Points

Jshell Error: Cannot Find symbol "Variable MAX_PEZ"

I am not able to find the variable (MAX_PEX) in jshell from the PezDispenser class Instance.

Code:

class PezDispenser{

public final int MAX_PEZ = 12; final private String characterName;

public PezDispenser(String characterName) { this.characterName = characterName; }

public String getCharacterName() { return characterName;

}

}

Jshell:

jshell> /open PezDispenser.java; jshell> PezDispenser pd = new PezDispenser("Yoda"); pd ==> PezDispenser@4c70fda8 jshell> pd.MAX_PEZ;

Following error displayed Error:
| cannot find symbol
| symbol: variable MAX_PEZ
| pd.MAX_PEZ;
| ^--------^

Code was saved before executing Jshell. Can anyone help me with this error?

1 Answer

Saad Hamid
Saad Hamid
3,150 Points

I executed "/open PezDispenser.java " command again and then created a new object from PezDispenser class and then i was able to access the fields of the class i.e (int MAX_PEZ)

This issue is fixed now!.