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 trialNikhil Radhakrishnan
1,613 PointsWhen creating a PezDispenser Object inside the repl it says NoSuchElementException ,Wht to do?
When i write
PezDispenser pd = new PezDispenser("Yoda"); java.util.NoSuchElementException
7 Answers
Craig Dennis
Treehouse TeacherTry running javac PezDispenser.java and make sure it compiles.
Ben Morse
6,068 PointsWhen I ran the javac command outside the java-repl, i was able to see my misspelling and undefined variables (more misspelling). After running javac for the third time, I received no errors. I went back into repl command line and typed in PezDispenser pd = new PezDispenser("Yoda"); and it worked. No java.util.NoSuchElementException error.
Craig Dennis
Treehouse TeacherSorry, not in the REPL on the command line. Trying to see if there is an error in the PezDispenser.java file.
Chris Vukin
17,787 PointsI had this same error, I hadn't removed the = from the public void we created and called return on. I removed the = after return and it worked great!
Sadat Kent McArthur
782 PointsI was getting this exception thrown because I wasn't loading the .class file. It immediately corrected itself once I typed: ": load PezDispenser.class".
shaunboleh
14,970 PointsI had this problem for a while, and only when I compiled it did I realize there was an error with isEmpty. The return type is boolean in the method signature, and had return mPezCount = 0 inside the { } which I guess is returning an integer. Everything was fixed once I added another equal sign, so like mPezCount == 0
Clarissa Cabbage
2,038 PointsI was having this error as well. I think the problem was that I didn't compile the code before entering the repl. Once I did compile it with javac PezDispenser.java I found that I had an error (I capitalized the "p" in "public"). After correcting my error, everything worked!
Kenneth Myers
16,009 PointsKenneth Myers
16,009 PointsWhen I do this I get:
EDIT: nevermind found my error, had a typo in one of my mPezCounts and the above error was from trying to do "javac PezDispenser.java" in java-repl and not out of it in the normal console.
Nikhil Radhakrishnan
1,613 PointsNikhil Radhakrishnan
1,613 PointsCraig Dennis U mean to say first i have to compile PezDispenser.java file and then use the :load command , but when we activate the repl we dont compile we just save the file n load. Its confusing !
Craig Dennis
Treehouse TeacherCraig Dennis
Treehouse TeacherNo I mean it seems that if the :load command isn't working, it might be a compile error that it isn't showing up in the REPL. Running javac will let you see the error (if there is one).