Problems getting data from a Label in JavaFX

0

Good afternoon, I am starting a simple example for the data acquisition of a Label in JavaFX, however I am having difficulties, most of the sources told me to perform as follows:

public class MainApp extends Application {

@FXML
private Label name;

@Override
public void start(Stage primaryStage) throws IOException {
    BorderPane root = FXMLLoader.load(getClass().getResource("RootLayout.fxml"));
    AnchorPane demo = FXMLLoader.load(getClass().getResource("Demo.fxml"));
    Scene scene = new Scene(root);
    primaryStage.setScene(scene);
    primaryStage.show();
    root.setCenter(demo);
    name.getText();
}

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

}

However, when I run the program the following error happens and I can not find the cause of it:

imgur [] [1] http: // error

I have already correctly added the controller class and the id that I declared in the controller in scene builder, follow the FXML code:

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

<?import javafx.scene.control.Label?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.text.Font?>

<AnchorPane prefHeight="300.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8.0.111" xmlns:fx="http://javafx.com/fxml/1" fx:controller="application.MainApp">
   <children>
      <Label fx:id="name" layoutX="241.0" layoutY="133.0" text="Label">
         <font>
            <Font size="29.0" />
         </font>
      </Label>
   </children>
</AnchorPane>
    
asked by anonymous 03.03.2017 / 19:36

1 answer

1

The Unknow Source error means that it could not find the fxml you specified, check the file name.

    
06.03.2017 / 14:03