0
我知道这个问题之前已经被问过好几次了,但没有一个答案对我来说是一个解决方案。我刚刚更新的JDK为java-8的OpenJDK-AMD64(从JDK7)和这些错误只是出现了:1778解决onAction时出现错误
javafx.fxml.LoadException: Error resolving onAction='#changeStyle', either the event handler is not in the Namespace or there is an error in the script./myapp.fxml:1778
线:
<Button layoutX="250.0" layoutY="170.0" mnemonicParsing="false" onAction="#changeStyle" text="Reset Style" />
控制器的.java:
public void changeStyle(){
String url_orig = CUSTOM_HTMLEditor.class.getClassLoader().getResource(pathToOrigCss).toExternalForm();
String url_1 = CUSTOM_HTMLEditor.class.getClassLoader().getResource(pathToStyle_1Css).toExternalForm();
String url_tango = CUSTOM_HTMLEditor.class.getClassLoader().getResource(pathToStyle_tangoCss).toExternalForm();
String url_tango_invers = CUSTOM_HTMLEditor.class.getClassLoader().getResource(pathToStyle_tangoInversCss).toExternalForm();
root_AnchorPane.getStylesheets().clear();
final Toggle selectedToggle = styleToggle.getSelectedToggle();
int selectedToggleIndex = styleToggle.getToggles().indexOf(selectedToggle);
switch(selectedToggleIndex)
{
case 0:
root_AnchorPane.getStylesheets().add(url_orig);
System.out.println("Style changed to original.");
currentPathToCSS = url_orig;
break;
case 1:
root_AnchorPane.getStylesheets().add(url_1);
System.out.println("Style changed to style_1.");
currentPathToCSS = url_1;
break;
case 2:
root_AnchorPane.getStylesheets().add(url_tango);
System.out.println("Style changed to tango.");
currentPathToCSS = url_tango;
break;
case 3:
root_AnchorPane.getStylesheets().add(url_tango_invers);
System.out.println("Style changed to tango_invers.");
currentPathToCSS = url_tango_invers;
break;
default:
root_AnchorPane.getStylesheets().add(url_orig);
System.out.println("Style changed to original.");
currentPathToCSS = url_orig;
}
}
设置控制器:
<AnchorPane id="root" fx:id="root_AnchorPane" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="500.0" minWidth="700.0" prefHeight="680.0" prefWidth="1000.0" xmlns="http://javafx.com/javafx/8.0.60" xmlns:fx="http://javafx.com/fxml/1" fx:controller="de.semproc.hergarten.gui.MemotrainerController">
编辑: 感谢您的帮助。这是该方法中的静态。
您可以编辑问题以显示您设置控制器的部分吗? –
我不认为你可以指定一个'static'方法作为处理程序。 (无论如何,它是没有意义的;处理程序是UI组件的属性,它必然是控制器*实例*的一个属性。) –