Scene Builder(JavaFx)中的错误切换场景

时间:2019-10-05 00:27:00

标签: java javafx scenebuilder

我正在尝试使用Scene Builder为大学活动创建图形界面。我需要在按下按钮时切换窗口,所以我创建了一个函数,该函数可以在按下按钮时更改窗口,并通过SceneBuilder在按钮上包含此操作,并且可以正常工作,但是当我尝试对按钮执行相同操作时在新窗口中出现此错误:

Executing C:\Users\Luke\Desktop\tp1\dist\run887860135\tp1.jar using platform C:\Program Files\Java\jdk1.8.0_221\jre/bin/java
out 04, 2019 7:05:11 PM javafx.fxml.FXMLLoader$ValueElement processValue
WARNING: Loading FXML document with JavaFX API of version 11.0.1 by JavaFX runtime of version 8.0.221
out 04, 2019 7:05:11 PM javafx.fxml.FXMLLoader$ValueElement processValue
WARNING: Loading FXML document with JavaFX API of version 11.0.1 by JavaFX runtime of version 8.0.221
Exception in Application start method
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 com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:389)
	at com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:328)
	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.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:767)
Caused by: java.lang.RuntimeException: Exception in Application start method
	at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:917)
	at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$1(LauncherImpl.java:182)
	at java.lang.Thread.run(Thread.java:748)
Caused by: javafx.fxml.LoadException: Error resolving onAction='#BTADDCLIENTEAction', either the event handler is not in the Namespace or there is an error in the script.
file:/C:/Users/Luke/Desktop/tp1/dist/run887860135/tp1.jar!/tp1/Cliente.fxml:8

	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.loadImpl(FXMLLoader.java:3214)
	at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3175)
	at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3148)
	at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3124)
	at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3104)
	at javafx.fxml.FXMLLoader.load(FXMLLoader.java:3097)
	at tp1.Tp1.start(Tp1.java:42)
	at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$8(LauncherImpl.java:863)
	at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$7(PlatformImpl.java:326)
	at com.sun.javafx.application.PlatformImpl.lambda$null$5(PlatformImpl.java:295)
	at java.security.AccessController.doPrivileged(Native Method)
	at com.sun.javafx.application.PlatformImpl.lambda$runLater$6(PlatformImpl.java:294)
	at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
	at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
	at com.sun.glass.ui.win.WinApplication.lambda$null$3(WinApplication.java:177)
	... 1 more
Exception running application tp1.Tp1
Java Result: 1

比我试图从此按钮中删除Action并编译了代码,因此错误可能出在该Action上,但我不知道如何解决,有人可以帮助我吗?

切换窗口的功能:

  private void BTADDCLIENTEAction(ActionEvent event) throws IOException {
        Parent main_parent = FXMLLoader.load(getClass().getResource("addCliente.fxml"));
        Scene ClienteScene = new Scene(main_parent);
        Stage mainStage =  (Stage) ((Node) event.getSource()).getScene().getWindow();
        mainStage.setScene(ClienteScene);
        mainStage.show();
    }

0 个答案:

没有答案