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

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!.