FXMLLoader.load () never exits (JavaFX 8)

I am trying to download the main screen for my application, which actually never starts and does not show the screen. After further investigation (running it through the NetBeans debugger), I found that my code never runs after FXMLLoader.load (url); - he stops there and does not cause any errors. I know that the url is correct - I checked its value and that is correct. Does anyone know how to fix this? Thanks in advance!


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

<?import java.lang.*?>
<?import javafx.scene.text.*?>

<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" fx:controller="graphics.MainScreenController">
<children>
<Text fx:id="funds" layoutX="489.0" layoutY="383.0" strokeType="OUTSIDE" strokeWidth="0.0" text="USD 52,356,000.07">
</Text>
</children></AnchorPane>

package graphics;

import java.io.IOException;
import java.net.URL;
import java.util.ResourceBundle;
import java.util.logging.Level;
import java.util.logging.Logger;
import javafx.application.Application;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.MenuButton;
import javafx.scene.control.MenuItem;
import javafx.scene.layout.VBox;
import javafx.scene.shape.Rectangle;
import javafx.scene.text.Text;
import javafx.stage.Stage;

/**
 * FXML Controller class
 *
 */
 public class MainScreenController extends Application implements Initializable {


@FXML
private Text funds;

/**
 * Initializes the controller class.
 */
public void initialize(URL url, ResourceBundle rb) {  
    start(new Stage());

}    

@Override
public void start(Stage primaryStage){
    Parent root = null;
    try {
        URL url = getClass().getResource("MainScreen.fxml");
        root = FXMLLoader.load(url);
    } catch (Exception ex) {
        Logger.getLogger(MainScreenController.class.getName()).log(Level.SEVERE, null, ex);
    }
    Scene scene = new Scene(root,1200,800);
    primaryStage.setTitle("Title");
    primaryStage.setScene(scene);
    primaryStage.show();
}

}
+4
source share
5 answers

You created an endless loop with the initialize () method. The initialization method is automatically called by FXMLLoader.

start() initialize(), MainScreen.fxml, MainScreenController. FXMLLoader initialize() , start(), MainScreen.xml .. .

JavaFX 2.2 Initializeable FXML. @FXML. " " , JavaFX? .

, , Stage() initialize(). Stage launch() , start() Stage . : http://docs.oracle.com/javafx/2/get_started/hello_world.htm

+4

JavafX-.

:

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

.

, http://docs.oracle.com/javafx/2/get_started/hello_world.htm .

+1

JavaFX-.

main static launch

:

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

launch start.

, http://docs.oracle.com/javafx/2/get_started/hello_world.htm,

,

.

0

. . , , .. TDD unit test FXML . @FXML.

, , , :

  • primaryStage.show();

:

  • initialize (URL url, ResourceBundle rb)

JavaFX . Netbeans: JavaFX Application "(). JavaFX start(). () main().

Netbeans:

  • /
    • /
      • Maven... ( )
        • JavaFX
      • JavaFX...
        • JavaFX

"Maven:: JavaFX Application" , Simple. , FXML. FXML "" .

, Start() LoadFXML (...), initialize(), :

  • FX: = "graphics.MainScreenController"

, , , :

  • , FXML URL-, : "MainScreen.fxml"
  • fx: id= "componentName" FXML " @FXML" (). , , NullPointerException. , .
  • . " @FXML" (code-behind), fx: id FXML, .
    • Scene Builder. - fx: id = "myList" fx: id = "myList1", , cut-n-paste. .

. FXML-....

. JavaBX Netbeans. Maven, FXML, CSS .. .

JavaFX: try/catch, logging,... JavaFX, , , . FXML , Java- - FXML, CSS .

, JavaFX, .,.

0

, , .

, , NullPointerException.

0

Source: https://habr.com/ru/post/1544514/


All Articles