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 trialTimea Toth
2,668 PointsError: Main method not found in class PezDispenser
Hi Guys! I double cheked all the code-s, it seems to me the same as Craig type them in the video, but I can't run the program because I've got an error message: Error: Main method not found in class PezDispenser, please define the main method as: public static void main(String[] args) or a JavaFX application class must extend javafx.application.Application
Here is my code: https://w.trhou.se/t47j1s267u
Please help :) THX
2 Answers
Kenneth Kinsey
14,897 PointsYou need to create the main method within the PezDispenser class to run the app. Java won't be able to run without it, as it is where it looks to initialize the app. Here's the best reference I could find on the topic if you're still pretty new to Java (it's old, but the information is still relevant): http://www.cs.princeton.edu/courses/archive/spr96/cs333/java/tutorial/java/anatomy/main.html
Truxton Stevens
28,536 PointsI think your code looks fine. You might be trying to run the wrong file though! Are you trying to compile your Example.java file or PezDispenser.java file? The Example.java file has the "public static void main" line in it, so this is the file that you need to compile and run. If you try running just the PezDispenser.java file by itself the compiler will get upset as there is no longer a main method and you'll get the error message you shared above! Good luck!