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

Why do I keep getting java.util.NoSuchElementException?

Hi I am on the Helper Methods and conditionals video and I'm completely confused on why I keep getting the error java.util.NoSuchElementException. I've seen some other people with similar errors but can't seem to figure out what I'm doing wrong. Here is what I have:

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 mPezcount == 0; }

public void load() { mPezCount = MAX_PEZ; }

public String getCharacterName() { return mCharacterName; } }

and in my console:

java> PezDispenser pd = new PezDispenser ("Yoda"); java.util.NoSuchElementException

would really appreciate any help on this!

2 Answers

Hi there,

In your isEmpty method, you have used Pezcount, not PezCount. That capital C may be the cause.

The variable is called PezCount in the class so you need to use that same spelling whenever you use the variable.

Steve.

Thanks so much for the help got it now!

No problem! Glad you got it fixed.

Steve. :+1: