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 Final

I am not getting the output with the following code. I am using Netbeans 8.2 as my code editor.

Source package name is hangman.java.objects.pkgnew and the two Files are as follows:

          <p>This is code!</p>

Example.java
package hangman.java.objects.pkgnew;
import hangman.java.objects.pkgnew.PezDispenser;
public class Example{
    public static void main(String[] args) {
        System.out.println("We are making a new pez dispenser!");
        PezDispenser dispenser = new PezDispenser("Donatello");
        System.out.printf("The dispenser is %s %n", dispenser.getCharacterName());
        String before = dispenser.swapHead("Darth vader");
        System.out.println("%s changed to %s %n", before, dispenser.getCharacterName());//Error in this line
}
}
          <p>This is code!</p>
PezDispenser.java
package hangman.java.objects.pkgnew;


public class PezDispenser {
   String characterName;

   public PezDispenser(String characterName){
       this.characterName = characterName;

   }

   public String getCharacterName(){
       return characterName;
   }

   public String swapHead(String characterName){
       String originalCharacterName = this.characterName;
       this.characterName = this.characterName;
       return originalCharacterName;
   }
}
          ```

What errors are you seeing?

I have solved it now. Thanks for being with me! The standard editors are not even compile the code I have written as above. I have to delete the code for swaphead method and also deleted the the line getting error as the code is wrong, very wrong.