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 (Retired) Harnessing the Power of Objects Helper Methods and Conditionals

wait what? What does this mean?

I don't think I understand why I am getting this error message.

Exception in thread "main" java.lang.NoSuchMethodError: PezDispenser.<init>(Ljava/lang/String;)V
at Example.main(Example.java:6)

Here is the code I think its referring to;

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");
    }

}

}

1 Answer

Alexander Nikiforov
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Alexander Nikiforov
Java Web Development Techdegree Graduate 22,175 Points

Looks like you have problem in PezDispenser class.

Could you post it ?

The error says that there is no constructor with one argument, that is Strting

public class PezDispenser {
   // system cannot find constructor below 
   public PezDispenser(String string) {
      // some code
   }
}

Also since you are clearly using Workspaces. Please Fork a Workspace and share a link here.

That is the fastest and easiest way to find a problem.

If you don't know how to fork a workspace, please watch this very short video that will show you how to do it

https://teamtreehouse.com/library/previews-and-snapshots