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 trial

Java Java Objects (Retired) Harnessing the Power of Objects Methods and Constants

ERROR: 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;
Ken Alger
Ken Alger
Treehouse Teacher

Li;

Can you post your code from PezDispenser.java?

Ken

7 Answers

reload the workspace..start a new one

I'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
STAFF
Craig Dennis
Treehouse Teacher

Wondering if your code isn't saved....

I saved the file but It is still not work. :(

I 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 :)

Still not work... :(

I 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
STAFF
Craig Dennis
Treehouse Teacher

Looks 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.