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

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.