Reputation: 11
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
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();
}
Upvotes: 0
Views: 1812
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
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