I have a common controller, from which I want to get a link to the controller of the internal element of the scene, quote the class code:
public class RootViewController { private DocumentTableOverviewController documentController; private Stage primaryStage; private BorderPane rootPane; private ObservableList<RailroadDocument> documentList = FXCollections.observableArrayList(); public void initController(){ initRootPanel(); initDocumentPanel(); } private void initDocumentPanel(){ try { FXMLLoader loader = new FXMLLoader(); loader.setLocation(RootViewController.class.getResource("components/DocumentTableOverview.fxml")); AnchorPane docTable = (AnchorPane)loader.load(); rootPane.setCenter(docTable); documentController = loader.getController(); //Вставил задержку, чтобы убедиться что ссылка активна new Thread(new Runnable() { @Override public void run() { try{ Thread.currentThread().sleep(3000); }catch(InterruptedException e){ } System.out.println(documentController);// ссылка активна != null } }).start(); } catch (IOException e) { e.printStackTrace(); } } private void initRootPanel(){ try { FXMLLoader loader = new FXMLLoader(); loader.setLocation(RootViewController.class.getResource("RootView.fxml")); rootPane = (BorderPane)loader.load(); } catch (IOException e) { e.printStackTrace(); } } //Метод привязан к кнопке test приложения @FXML public void testButtonAction(){ System.out.println(documentController);//Ссылка == null } } When the testButtonAction() method is called, the reference is zero. I don’t understand why this is the case, because specifically in the initialization method I set sleep for 2 seconds to make sure that the link remains active. It feels like the testButtonAction() method is executed in another application, in which documentController == null;