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 trialArjun Vemperala
1,212 PointsHelper methods and conditionals video
Hi there i am getting some errors in my workspace even though i am exactly following as per instructions in the video
when i type this code in repl PezDispenser pd = new PezDispenser("Yoda");
i am getting either one of these 2 errors
1.Error: cannot find symbol
symbol: class PezDispenser
location: interface Evaluation
PezDispensr method$doepy29rc8sfxi4vk6ln();
- java.util.NoSuchElementException
i have attached a snapshot of the worksheet thanks in advance
3 Answers
Simon Coates
28,694 Pointspublic class PezDispenser{
public static final int MAX_PEZ = 12;
public String mCharacterName;
private int mPezCount;
public PezDispenser(String characterName){
mCharacterName = characterName;
mPezCount = 0;
}
public Boolean isEmpty(){
return mPezCount ==0;
}
public void load(){
mPezCount = MAX_PEZ;
}
public String getCharacterName(){
return mCharacterName;
}
}
and
public class Example {
public static void main(String[] args) {
// Your amazing code goes here...
System.out.println("We are making a new Pez Dispenser.");
PezDispenser dispenser = new PezDispenser("Yoda");
System.out.printf("The Dispenser character is %s\n",
dispenser.mCharacterName);
}
}
produces
treehouse:~/workspace$ javac PezDispenser.java
treehouse:~/workspace$ javac Example.java
treehouse:~/workspace$ java Example
We are making a new Pez Dispenser.
The Dispenser character is Yoda
treehouse:~/workspace$
Arjun Vemperala
1,212 Pointschecked the code and even copy pasted your code but still getting the same error
Simon Coates
28,694 Pointsyou are recompiling your java after your change it? After you recompile with the above code, you should be able to enter
java Example
into the console. I deliberately included the java and javac commands with my earlier answer.
Arjun Vemperala
1,212 Pointsi am doing the 2 steps not sure if its recompiling 1):load PezDispenser.java Loaded source file from PezDispenser.java
2) PezDispenser pd = new PezDispenser("Yoda");
ERROR: cannot find symbol symbol: class PezDispenser location: interface Evaluation
Simon Coates
28,694 PointsSimon Coates
28,694 Pointsso based on what treehouse gave me, you were missing the } to close the class, and had a duplicate method in PezDispenser. I didn't get the exception you seemed to get.
Arjun Vemperala
1,212 PointsArjun Vemperala
1,212 Pointsgot it, i launched a new worksheet and the code worked just fine your explanation also helped me a lot and most of all i learnt from my mistakes thanks a lot man.