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 (Retired) Harnessing the Power of Objects Methods and Constants

Martin Turner
Martin Turner
1,757 Points

ERROR: Cannot find symbol (MAX_PEZ)

Hi all,

I'm using the java-repl to follows the steps on the Methods and Constants video; as far as I can see, my code is identical; however, after created the new PezDispenser object as name pd, when I input pd.MAX_PEZ I get the following error message:

ERROR: cannot find symbol
symbol: variable MAX_PEZ
location: variable pd of type PezDispenser
pd.MAX_PEZ;;

Here's my code from the PezDispenser class:

public class PezDispenser { public final int MAX_PEX = 12; private String mCharacterName;

public PezDispenser(String characterName) { mCharacterName = characterName; }

public String getCharacterName() { return mCharacterName; } }

Many thanks!

1 Answer

The reason you get this error is the same reason you cant do java pd.mCharacterName;.

You have to create a get method to return the variable from the object. Adding a get method to return the pez count and then calling that method with the object will allow you to get pez count (or max pez).