-3

I'm a beginner in programming and I'm having an issue when running a Java class. (I'm using Eclipse if it makes any difference). If I create a new class and tick the public static void main(String[] args) method, the code runs as usual. However, if I don't tick the mentioned method, I can't run it "as a Java app" so I have to "run configurations" and then get the error:

Error: Main method not found in class katrina.Six, please define the main method as:
   public static void main(String[] args)
or a JavaFX application class must extend javafx.application.Application

So, why can't I run a non-main class (if it can be thus called), and how do I extend javafx.application.Application ??? Also, does this mean I always have to use the main method and if yes, then why?

I know I suck at this.

Thanks

  • 1
    There is no such thing as a "main-class". But, yes, if you run a standalone Java app, you'll need to start it through a main method, because that is how the language is designed. If you don't know this, don't start with Java FX, but start learning the basics first. – Stultuske Jun 04 '15 at 19:46
  • Yes you must have a `main` method in your `Java` class if you want to "run" it... – brso05 Jun 04 '15 at 19:46
  • 3
    Yes, you need a main _method_ in order to run your code. If you're a beginner, you really probably shouldn't be even coming close to touching JavaFX until you learn the bare basics first. – Ricky Mutschlechner Jun 04 '15 at 19:47
  • http://stackoverflow.com/questions/7443459/why-main-method-is-needed-in-java-main-class – froadie Jun 04 '15 at 19:47
  • Understand that public static void main(String[] args) is necessary, because how else would the JVM know where to start your program? Within the main method, you can access methods defined in that class as well as in others. All it is is an entry point – ControlAltDel Jun 04 '15 at 19:53
  • Is that even JavaFX? Idk I just watched the thenewboston tutorials on Java and I thought they were the basicest :\ – Debugging Life Jun 04 '15 at 19:55
  • @DebuggingLife: it assumes you know how to compile, write, run java applications, how can it be the basics? first learn the language, it's syntax, write simple non-OO programs, test and debug, learn to package them, run them. Then learn the OO basics. if you learn it decently, with a few hours each day, expect to spend about a year over the basics alone, if you actually plan on understanding them. – Stultuske Jun 04 '15 at 19:57

1 Answers1

0

Thanks to a bunch of very helpful commenters above, I was able to answer (even though not fully, but at least it's better than nothing) my own question a couple of days later.

Yes, we need the main method in general, but sometimes, eg if you're inheriting a method from another class (as was in my case), you don't need to put the public static void main(String[] args) in the class you're overriding from.

@ Stultuske, @ Ricky Mutschlechner the existence of the word "Java FX" in the error message doesn't necessarily mean you're using Java FX.

@ Stuluske I did learn a non-OO program but I still call myself a beginner because I acknowledge my ignorance of some basic programming.