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


Nelson Watson
Nelson Watson
4,511 Points

Main Method Not Found Error

I'm stuck. I'm in the Java track, and I'm working in the Pez_Dispenser program section of the course. I've resorted to just flat-out copying the code from the instructor line by line just to get it to work so I can figure out what I'm doing wrong. Can someone point out what's giving me the "Main method not found in class, please redefine the method as.." error?

class PezDispenser {
  public static final int MAX_PEZ = 12;
  final private String characterName;
  private int pezCount;

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

  public void fill() {
    pezCount = MAX_PEZ;

  public String getCharacterName() {
    return characterName;

} ```
Nelson Watson
Nelson Watson
4,511 Points

This is the specific error I'm getting: Error: Main method not found in class PezDispenser, please de fine the main method as:
public static void main(String[] args)
or a JavaFX application class must extend javafx.application. Application

1 Answer

What you have above is the PezDispenser class, but without a main method you cannot do anything with the class. A main method will have public static void main(String[] args) this is where you can create a pezDispenser variable and call all of its methods.