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 Helper Methods and Conditionals

getting java.util.NoSuchElementException and errors with my code

I am following the tutorial Helper Methods and Conditionals and seem to have the same code as the teacher, but i am still getting errors and i don't know why.

Here is my code:


public class PezDispenser { public static final int MAX_PEZ = 12; private String mCharacterName; private int mPezCount;

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

public boolean isEmpty() { return PezCount == 0; }

public void load() { mPezCount = MAXPEZ; }

public String getCharacterName() { return mCharacterName; } }


And this is my console after trying to use repl and the trying to compile the code to see if it would solve my problem with repl:


java> :load PezDispenser.java
Loaded source file from PezDispenser.java
java> PezDispenser pd = new PezDispenser("Yoda");
java.util.NoSuchElementException
java>
Terminating...
treehouse:~/workspace$ javac PezDispenser.java
PezDispenser.java:12: error: cannot find symbol
return PezCount == 0;
^
symbol: variable PezCount
location: class PezDispenser
PezDispenser.java:16: error: cannot find symbol
mPezCount = MAXPEZ;
^
symbol: variable MAXPEZ
location: class PezDispenser
2 errors
treehouse:~/workspace$


1 Answer

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi there! Well I can point out at least one error. You have written this:

public static final int MAX_PEZ = 12;

This declares a variable named MAX_PEZ.

But later on in your error messages we see this:

PezDispenser.java:16: error: cannot find symbol
mPezCount = MAXPEZ;

So if we look up a bit in your code we see this:

public void load() { 
    mPezCount = MAXPEZ;
 }

You forgot the underscore between MAX and PEZ. That should be MAX_PEZ... not MAXPEZ. Hope you get this working! :sparkles: