0

I am trying to start a javafx project but when I have started and run the application the GUI does not appear.

Main.Java

package application;

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


public class Main extends Application {
    @Override
    public void start(Stage primaryStage) {
        try {
            BorderPane root = (BorderPane)FXMLLoader.load(getClass().getResource("Sample.fxml"));
            Scene scene = new Scene(root,400,400);
            scene.getStylesheets().add(getClass().getResource("application.css").toExternalForm());
            primaryStage.setScene(scene);
            primaryStage.show();
        } catch(Exception e) {
            e.printStackTrace();
        }
    }

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

sample.fxml

<?xml version="1.0" encoding="UTF-8"?>

<!-- 
    Do not edit this file it is generated by e(fx)clipse from ../src/application/Sample.fxgraph
-->

<?import javafx.scene.layout.*?>
<?import java.lang.*?>
<?import javafx.scene.layout.BorderPane?>


<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" />

OUTPUT

Windows/x86_64 

and there is no GUI is appearing on screen.

Kinly help

amoaa001
  • 1
  • 1
  • This throws an exception when I run it: the error message you should get will tell you what is wrong. How are you running this? Don't you see a [stack trace](http://stackoverflow.com/q/3988788/2775450) in the console? – James_D May 17 '17 at 19:43
  • 1
    Just from glancing at it, you are trying to load a `BorderPane` and your `fxml` is an `Anchorpane`. – Hypnic Jerk May 17 '17 at 19:51
  • I have change the BorderPane to Anchorpane in both and still the same and I am not getting any err in stack trace all what I get is Windows/x86_64 and cause of that I cannot figure what is the problem – amoaa001 May 17 '17 at 20:46
  • try this: `Parent root = FXMLLoader.load(getClass().getResource("Sample.fxml"));` and comment out the css code until you have fixed this problem. – SedJ601 May 17 '17 at 21:27
  • I can only conclude that you are not actually running the code you posted. As I asked 4 hours ago: how are you running this? – James_D May 18 '17 at 00:16
  • I am running it through eclipse and same thing – amoaa001 May 18 '17 at 05:32
  • thanks I found the problem it was related to naming (duplicate application naming) and eclipse was confused with application to run. – amoaa001 May 18 '17 at 05:43

0 Answers0