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
Amit Dhamankar
4,163 Pointsjava.util.NoSuchElementException
I am getting this error. I saw the answer to the previously asked question but I was not satisfied with the answer. When I try this command after starting java-repl i typed the following commad which is:
PezDispenser pd = new PezDispenser("Yoda"); Thanks in advance
1 Answer
moonshine
8,449 PointsThat could because there is no element PezDispenser. According to the documentation:
Thrown by various accessor methods to indicate that the element being requested does not exist.
Your expression should work fine if you defined a class PezDipsenser.
class PezDispenser {
PezDispenser(String name) {
/* . . . */
}
/* . . . */
}
Amit Dhamankar
4,163 PointsAmit Dhamankar
4,163 Pointsclass PezDispenser { public static final int MAX_PEZ = 12; private String mCharacterName; private String mPezCount;
PezDispenser(String characterName){ mCharacterName = characterName; mPezCount = 0; } public boolean isEmpty() { return mPezCount == 0; }
public String getmCharacterName(){ return mCharacterName; }
public void load() { mPezCount = MAX_PEZ; }
}
This code still isn't working? Whats the problem
moonshine
8,449 Pointsmoonshine
8,449 PointsThe error message I get is:
Does converting
mPezCountto anintmake it work?