Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Java Java Objects (Retired) Harnessing the Power of Objects Incrementing and Decrementing

./PezDispenser.java:16: error: ';' expected

i'm getting an error

that's my Example.java

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 dispnenser chracter is %s\n",
      if (dispenser.isEmpty()) {
      System.out.println("It's curently empty");


      if (!dispenser.isEmpty()) {
      System.out.println("It's not longer empty");

      while (dispenser.dispense()) {
      if (dispenser.isEmpty()) {
      System.out.println("Ate all the PEZ");

and this is PezDispenser.java

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 dispense() {
  boolean wasDispensed = false;
    if (!isEmpty()) {
      wasDispensed = true;
    return wasDispensed;

  public boolean isEmpty(){
  return mPezCount == 0;

  public void load() {

  mPezCount = MAX_PEZ;


  public String getCharacterName(){
    return mCharacterName;


in Console it's shows me this error

 ./PezDispenser.java:16: error: ';' expected                                                                                      
    return wasDispensed                                                                                                          
1 error  

then treehouse:~/workspace$ javac Example.java && java Example
We are making a new Pez Dispenser.
The dispnenser chracter is Yoda
It's curently empty

2 Answers

Seph Cordovano
Seph Cordovano
17,400 Points

You probably need to either save the new version where wasDispensed has the ";" at the end or if you're using the console recompile the saved version before running it again. Often beginners forget that they have to recompile after new saved versions. I recommend just chaining both commands:

$ javac Example.java && java Example

This will recompile both Example.java and PezDispenser.java since they are connected in the code.

Thanks! I was facing a similar problem. Recompiling did the trick

49,872 Points

return wasDispensed ; You forgot ; at the end

public boolean dispense() { boolean wasDispensed = false; if (!isEmpty()) { mPezCount--; wasDispensed = true; } return wasDispensed; }

i don't think that i forgot the semicolon