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 trialLi Chang
11,883 PointsERROR: not a statement; ERROR: cannot find symbol
Why this happen when I load PezDispenser.java on repl?
public class PezDispenser {
public static final int MAX_PEZ = 12;
private String mCharacterName;
private int mPezCount;
public PezDispenser (String characterName){
mCharacterName = characterName;
mPezCount = 0;
}
public void load(){
mPezCount = MAX_PEZ;
}
public boolean isEmpty(){ boolean isActuallyEmpty = mPezCount == 0; return isActuallyEmpty; }
//Creates a public class that gets the private object above.
// This was commented out
public String getCharacterName() {
return mCharacterName;
}
}
java> :load PezDispenser.java
Loaded source file from PezDispenser.java
java> PezDispenser.MAX_PEZ
ERROR: not a statement
PezDispenser.MAX_PEZ;
^
ERROR: cannot find symbol
symbol: variable PezDispenser
location: class Evaluation
PezDispenser.MAX_PEZ;
7 Answers
Nikhil Radhakrishnan
1,613 Pointsreload the workspace..start a new one
Kenneth Myers
16,009 PointsI'm not sure if you got this working but I was getting the exact same error when I tried to pass "PezDispenser.Max_Pez" instead of "PezDispenser.MAX_PEZ" which may mean you have a typo somewhere (I couldn't find it in your code though).
Hope this helps someone else who's getting this error.
Craig Dennis
Treehouse TeacherWondering if your code isn't saved....
Li Chang
11,883 PointsI saved the file but It is still not work. :(
Nikhil Radhakrishnan
1,613 PointsI got the same error .. so i saved the file even it is saved and again reloaded the java file using the load command and it worked for me :)
Li Chang
11,883 PointsStill not work... :(
Steve Brewer
15,030 PointsI have the exact same error:
treehouse:~/workspace$ javac Example.java
./PezDispenser.java:12: error: cannot find symbol
return isActuallyEmpty = mPezCount == 0;
^
symbol: variable isActuallyEmpty
location: class PezDispenser
1 error
My PezDispenser.java looks like this:
public class PezDispenser {
public static final int MAX_PEZ = 12;
private String mCharacterName;
private int mPezCount;
public PezDispenser(String characterName) {
mCharacterName = characterName;
mPezCount = 0;
}
public boolean isEmpty() {
return isActuallyEmpty = mPezCount == 0;
}
public void load() {
mPezCount = MAX_PEZ;
}
public String getCharacterName() {
return mCharacterName;
}
}
Craig Dennis
Treehouse TeacherLooks like that line where you declare isActuallyEmpty
is missing. Not sure exactly where you are at, but if you remove that and make the line:
return mPezCount == 0;
It will be much happier.
Hope that helps.
Ken Alger
Treehouse TeacherKen Alger
Treehouse TeacherLi;
Can you post your code from
PezDispenser.java
?Ken