Problems acquiring data from a Javafx Label

Asked

Viewed 143 times

0

Good afternoon, I’m starting a simple example for data acquisition of a Label in Javafx, but I’m 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’t find the cause of it:

Imgur[][1] http://error

I already correctly added the controller class and id I declared in the controller in Scene Builder, follows 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>

1 answer

1

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.