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 trialDan B
6,155 PointsAdded the isEmpty() function which returns mPezCount == 0; now getting this error: "java.util.NoSuchElementException"
So I added the following to my PezDispenser.java
public boolean isEmpty() {
return mPezCount == 0;
}
Now when I run the following command in the repl:
PezDispenser pd = new PezDispenser("Yoda");
I get this error:
java.util.NoSuchElementException
What have I done wrong? My PezDispenser.java looks the same as the teacher's...
2 Answers
osman musse
100 PointsWhat's wrong with my one
osman musse
100 Pointspublic class PezDispenser {
public String mCharacterName;
public PezDispenser (String characterName) { mCharacterName = characterName; mCountPez = 0;
}
public boolean isEmpty() {
return mCountPez == 0; } pulbic void load() { mPezCount = MAX_PEZ; }
public static final int MAX_PEZ = 12; public int mPezCount;
public String getCharacterName() { return mCharacterName; }
}
Dan B
6,155 PointsDan B
6,155 PointsI'll answer this myself. I actually had a tiny 'fullstop' in my PezDispenser.java in one of the lines that was throwing the exception. After scanning the file carefully and removing it, and loading it again, it compiled without any issues.