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 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,520 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.