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

My Example.java isn't running. can someone help me.

Here is my example.java codes :

public class Example {

public static void main(String[] args) {
    // Your amazing code goes here...

System.out.println("We are a making a new Pez Dispenser.");

   PezDispenser dispenser = new  PezDispenser("Yoda");

  System.out.printf("The dispenser character is %s\n", dispenser.getCharracterName());

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.dipense()) {
  System.out.println("chomp!");

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

dispenser.load(4); dispenser.load(2); while(dispenser.dipense()) { System.out.println("chomp!");

   }

}

and here is the error message :

System.out.println("chomp!");                                 
             ^                                                  

Example.java:28: error: illegal start of type
System.out.println("chomp!");
^
Example.java:32: error: class, interface, or enum expected
}

help me friends..

1 Answer

Your code is hard to read because of how you pasted it. I believe your problem is because of your curly braces. Make sure that the main method's closing curly brace is the second to last curly brace, followed by your class's closing curly brace and then try again. If that doesn't work, re paste your code and DON'T break it up between 5 code blocks with some of the code in between the code blocks.

Seeing as how you didn't include PezDispenser.java I'm assuming that your code in that file is all correct when you're calling those methods.