0

JavaFX application class must extend javafx.application.Application --> Getting this error eventhough main method is there.

Please refer to my sample code:

package testpkg;

class Overloading1 {
public void disp(char c) {
    System.out.println(c);
}

public void disp(char c, int num) {
    System.out.println(c + " " + num);
}

}

class Overloading2 extends Overloading1 {

public static void main(String args[]) {
    Overloading2 obj = new Overloading2();
    obj.disp('a');
    obj.disp('a', 10);
}

}

6
  • 1
    is that all in an Overloading1.java file? also: what has any of this got to do with JavaFX? Commented Oct 12, 2018 at 12:14
  • Yes all that code written in Overloading1.java file. Commented Oct 12, 2018 at 12:18
  • why would you put a main method in a non-public class? Commented Oct 12, 2018 at 12:19
  • If i make Overloading2 class as public, then i am getting following error, The public type Overloading2 must be defined in its own file Commented Oct 12, 2018 at 12:23
  • 1
    Ya. Thanks for your feedback. I am in a beginner in Java. I just renamed the .java file as "Overloading2.java" and now code is getting executed without any error. Once again thanks a lot. Commented Oct 12, 2018 at 12:30

4 Answers 4

1

You are right, the normal java application has a main class with as entry point public static void main(String[] args).

However you created a JavaFX project, which by definitions puts its application code in a JavaFX specific Application class which your main class has to extend. The IDE tries to start a JavaFX application.

If you want to have the JavaFX GUI application, study a tutorial.

Otherwise create a normal java application project. (Which seems to be the case here.)

Sign up to request clarification or add additional context in comments.

Comments

1

Maybe your IDE project is set up wrongly as "JavaFx Application". Most IDEs call the normal java project type "Empty Project" or "Java Project".

Comments

0

It does not seem to be a Javafx issue. Create Separate files for both Classes with name Overloading1.java and Overloading2.java :

Overloading1.java :

class Overloading1 {
    public void disp(char c) {
        System.out.println(c);
    }

    public void disp(char c, int num) {
        System.out.println(c + " " + num);
    }

}

And Overloading2.java :

class Overloading2 extends Overloading1 {

    public static void main(String args[]) {
        Overloading2 obj = new Overloading2();
        obj.disp('a');
        obj.disp('a', 10);
    }
}

And try to run the Overloading2.java again. If still you are facing issue, check your launcher or environment settings.

Comments

0

Make sure the project is build successfully. If you are using eclipse, Check "Marker tab" for any error and fix.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.