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 trialAlina Sirbeanu
992 PointsPls Help!
This is the code in PezDispenser.java
public class PezDispenser{
public static final int MAX_PEZ = 12;
private String mCharacterName;
private int mPezCount;
public PezDispenser(String characterName){
mCharacterName = characterName;
mPazCount = 0;
}
public boolean isEmpty(){
return mPezCount == 0;
}
public void load(){
mPezCount = MAX_PEZ;
}
public String getCharacterName(){
return mCharacterName;
}
}
When i load it in repl it shows me this :
java> :load PezDispenser.java
Loaded source file from PezDispenser.java
java> PezDispenser pd = new PezDispenser("Yoda");
java.util.NoSuchElementException
Does anyone know what it is or where i make the mistake?
Thank you very much!
2 Answers
Craig Dennis
Treehouse TeacherWhoops!
mPazCount = 0;
Protip: If you call javac on the file, I think it will probably point to that error.
Alina Sirbeanu
992 PointsYou have totally right! I was running javac in PezDispenser : clear && javac PezDispenser.java && java PezDispenser. (My bad!)
I just run javac Example and is working! Then i load :
java> :load PezDispenser.java
Loaded source file from PezDispenser.java
java> PezDispenser pd = new PezDispenser("Yoda");
PezDispenser pd = PezDispenser@4800587f
And Yay!! is working.Thank you very much !!
Alina Sirbeanu
992 PointsAlina Sirbeanu
992 PointsHey Craig,
Cant believe that is really you! Awesome class!! Your clear and very funny :) Thank you for your replay,i resolve the bug with the mPazCount = 0; ,i save it and again it show me the same error:
I run javac and it says : Error: Main method not found in class PezDispenser, please define the main method as:
public static void main(String[] args)
or a JavaFX application class must extend javafx.application.Application
^
1 error
Craig Dennis
Treehouse TeacherCraig Dennis
Treehouse TeacherYou sure you ran
javac
and notjava
on the file? That error sounds very much like when you run the commandjava
on a class that does not have a main method (whichPezDispenser
doesn't have).