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

Whitney Barber
Whitney Barber
9,453 Points

The error message is calling for me to add a ";" where it does not belong. Please assist.

HERE'S THE ERROR MESSAGE...

treehouse:~/workspace$ javac Example.java                                                                  

Example.java:20: error: ';' expected                                                                       
      If (dispenser.isEmpty()) {                                                                           
                              ^                                                                            
Example.java:23: error: reached end of file while parsing                                                  
    }                                                                                                      
     ^                                                                                                     
2 errors 

AND HERE'S MY CODE...

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");
      }
      while (dispenser.dispense()) {
        System.out.println("chomp!");
      }
      If (dispenser.isEmpty()) {
        System.out.println("Ate all the PEZ!");
      }
    }

2 Answers

Jeremy Faith
PLUS
Jeremy Faith
Courses Plus Student 56,696 Points

Also, do you have a final bracket } to close your class. This could be why you are getting the error Example.java:23: error: reached end of file while parsing.

Chris Howell
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Chris Howell
Python Web Development Techdegree Graduate 49,610 Points

Try making your very last if statement all lowercase instead of the uppercase i. I believe they are case-sensitive, so this would cause an error to be thrown.

Whitney Barber
Whitney Barber
9,453 Points

That was a good catch! Thank you as well! I got it working now.