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 trialerinnbean
Courses Plus Student 406 PointsPezDispenser dispenser = new PezDispenser("Yoda");
Why would this error come up:
java.util.NoSuchElementException
I did not change the code from the previous section but I could not do the Methods and Commands workspace activity. :(
3 Answers
Andrea Miotto
iOS Development Techdegree Graduate 23,357 Pointsjava.util.NoSuchElementException is a RuntimeException which can be thrown by different classes in Java like Iterator, Enumerator, Scanner or StringTokenizer. All of those classes has method to fetch next element or next tokens if underlying data-structure doesn't have any element Java throws "java.util.NoSuchElementException".
Anyway if you would like to show us your code, maybe we can help you.
Kamran Khan
837 Points public class PezDispenser {
public static final int String mCharacterName;
public final int MAX_PEZ = 12;
public PezDispenser (String characterName) {
mCharacterName = characterName;
}
public String getCharacterName() {
return mCharacterName;
}
}
Kamran Khan
837 PointsI am getting the same thing, java.util.NoSuchElementException
Kelly Hughes
2,444 PointsHi Kamran,
I believe that there's some error in your second line of code: public static final int String mCharacterName;
- a variable cannot have two datatypes (int String) -the (public static final) portion is telling the compiler that the variable value will not change, but in this case, mCharacterName can change with each object.
Perhaps the code should be:
public static final int MAX_PEZ = 12;
String mCharacterName;
I hope that this helps :)
ISAIAH S
1,409 PointsISAIAH S
1,409 PointsCould I see your code?