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 Meet Objects Final

Error in final java objects

I keep receiving this error when I have the same code in my example.java

Example.java:13: error: ';' expected
dispenser.getCharacterName());

This is the 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 is %s %n", dispenser.getCharacterName() ); String before = dispenser.swapHead("Darth Vader"); System.out.printf("It was %s but Chris switched it to %s %n" before, dispenser.getCharacterName()); }

}

2 Answers

Mihai Craciun
Mihai Craciun
13,519 Points
This is the 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 is %s %n", dispenser.getCharacterName() ); 
String before = dispenser.swapHead("Darth Vader"); 
System.out.printf("It was %s but Chris switched it to %s %n" before, dispenser.getCharacterName()); 
  }
//^ this " } " is extra
}
Daniel Mallett
Daniel Mallett
14,582 Points

It looks like you have 1 too many closing braces at the end of your program. Or you just need to move the closing brace down one . Which means it is not picking up the semi-colon.