Wajahat Shah
Wajahat Shah

Reputation: 11

Exception in Application start method and FXML Scene Builder Error "Operation has been failed.Make sure that chosen file is a valid FXML Document"

When i made my GUI by Scene builder it was working fine on eclipse and i save this. And i re-open eclipse then this error show.Whenever i created a new project and re-open eclipse / restart computer , it shows me this message every-time. And When i tried to open my FXML document is says "**

Open Operation has been failed.Make sure that Chosen file is a valid FXML Document

ClLICK HERE TO SEE THE ERROR MESSAGE -This is the message that FXML Document show me when i restart my computer. It show this for every-time for every project.

Please Help me Here is the Code

 package application;

public static void main(String[] args) {
     launch(args);
}

@Override
public void start(Stage primaryStage) throws Exception {

    Parent root = FXMLLoader.load(getClass().getResource("MyDocmnt.fxml"));
    Scene scene = new Scene(root);
    primaryStage.setTitle("My Tittle");
    primaryStage.setScene(scene);
    primaryStage.show();

}

CLICK HERE TO SEE THE ERROR - this is the error it show me on running the code

Upvotes: 0

Views: 1812

Answers (2)

alps_ren
alps_ren

Reputation: 11

javafx.application.Application class is an abstract class. And start() method is an abstract method of Application class.

In Java, we have to implement all the abstract methods of an abstract class when extending that abstract class. Here, we are implementing the abstract method (start() method) by overriding the start() method.

So, try this:

package application;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;

    public class Main extends Application{

            public static void main(String[] args) {
                 launch(args);
            }

            @Override
            public void start(Stage primaryStage) throws Exception {

                Parent root = FXMLLoader.load(getClass().getResource("MyDocmnt.fxml"));
                Scene scene = new Scene(root);
                primaryStage.setTitle("My Tittle");
                primaryStage.setScene(scene);
                primaryStage.show();

            } 
    }

Upvotes: 0

Nevets17
Nevets17

Reputation: 109

Try this:

package application;

import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.stage.Stage;
import javafx.scene.Parent;
import javafx.scene.Scene;

    public class Main extends Application {

                @Override
                public void start(Stage primaryStage) {
                    try {
                        Parent root = FXMLLoader.load(getClass().getResource("/application/MyDocmnt.fxml"));
                        Scene scene = new Scene(root);
                        primaryStage.setTitle("My Title");
                        primaryStage.setScene(scene);
                        primaryStage.show();
                    } catch(Exception e) {
                        e.printStackTrace();
                    }
                }

        public static void main(String[] args) {
             launch(args);
        }

    }

Upvotes: 0

Related Questions