有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

解析操作“…”时发生java错误,试图从另一个控制器调用控制器

我正在创建一个FXML项目,在FXML上有一个按钮,我想带我去一个新的场景

这个新场景有一个新的控制器,我在其中实现了一个函数,我想从原始控制器调用这个函数(因为我正在尝试实现OOP)

我是这样做的:

    @FXML
    public void resultsAndFixturesScreen(ActionEvent event) throws IOException {

        FXMLLoader loader = new FXMLLoader(getClass().getClassLoader().getResource("Login/res/fixturesAndResults.fxml"));
        Parent root = loader.load();

        FixturesAndResultsController scene2 = loader.getController();
        scene2.table(teams);

        Scene scene = new Scene(root);

        Stage stage = (Stage) ((Node) event.getSource()).getScene().getWindow();

        stage.setScene(scene);
        stage.show();

    }

这是我想在新控制器中调用的新函数:

public class FixturesAndResultsController implements Initializable {

    @FXML Label fixturesLabel;

    public void table(TeamList teams){
        for (Team t: teams.getTeamList()){
            System.out.println(t);
            fixturesLabel.setText(teams.toString());
        }
    }

    @Override
    public void initialize(URL location, ResourceBundle resources) {

    }
}

这一切对我来说都很好,没有这个功能,我可以改变场景,所以这不是问题,但是我收到了这个堆栈跟踪:

Caused by: java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at sun.reflect.misc.Trampoline.invoke(MethodUtil.java:71)
    at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at sun.reflect.misc.MethodUtil.invoke(MethodUtil.java:275)
    at javafx.fxml.FXMLLoader$MethodHandler.invoke(FXMLLoader.java:1769)
    ... 52 more
Caused by: javafx.fxml.LoadException: Error resolving onAction='#table', either the event handler is not in the Namespace or there is an error in the script.
/C:/Users/44742/IdeaProjects/OOSDCw2.1/out/production/OOSDCw2.1/Login/res/fixturesAndResults.fxml:9

    at javafx.fxml.FXMLLoader.constructLoadException(FXMLLoader.java:2597)
    at javafx.fxml.FXMLLoader.access$100(FXMLLoader.java:103)
    at javafx.fxml.FXMLLoader$Element.processEventHandlerAttributes(FXMLLoader.java:610)
    at javafx.fxml.FXMLLoader$ValueElement.processEndElement(FXMLLoader.java:770)
    at javafx.fxml.FXMLLoader.processEndElement(FXMLLoader.java:2823)
    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2532)
    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2441)
    at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2409)
    at Login.controllers.AdminController.resultsAndFixturesScreen(AdminController.java:107)
    ... 62 more

在新的场景中,table函数被设置到一个按钮上,我不确定问题可能是什么


共 (0) 个答案