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 Helper Methods and Conditionals

Maxwell Nelson
Maxwell Nelson
9,465 Points

ERROR: Not a statement

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.getCharacterName()); 
    if (dispenser.isEmpty()) {
      System.out.println("It is currently empty.");   
    }
    System.out.println("Loading...");
    dispenser.load();
    if (!dispenser.isEmpty()) {
      System.out.println("It is no longer empty.");
    }      
} 

}

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 mPezCount == 0; }

public void load() { mPezCount = MAX_PEZ;
}

public String getCharacterName() { return mCharacterName; } }

Here are 2 classes I have for the pez dispenser gig. I do not know what it is that is wrong with my code but I am receiving this error. I went line by line with Craig and it all appears to match up. What am I doing wrong? Error below:

ERROR: not a statement
clear && javac Example.java && java Example;
^
ERROR: ';' expected
clear && javac Example.java && java Example;
^
ERROR: not a statement
clear && javac Example.java && java Example;
^

Thanks in advance!

Maxwell Nelson
Maxwell Nelson
9,465 Points

It is also saying

ERROR: not a statement "Java Example;" ^

(if this formatting jacks up, the arrow is pointing at the E in Example.)

1 Answer

Maxwell Nelson
Maxwell Nelson
9,465 Points

Figured this out, if you get this error do not compile it in java-repl. Instead, compile it in the console's default treehouse:~/workspaces so, for example:

"treehouse:~/workspaces clear && javac Example.java && java Example"