2016-08-15 45 views
0

これは数回前に尋ねられましたが、私の解決策は何も見つかりませんでした。私はただのjava-8-OpenJDKの-AMD64(JDK7から)にJDKを更新し、これらのエラーは、ちょうど登場: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 

ライン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"> 

編集: 助けてくれてありがとう。それはメソッドの静的だった。

+0

コントローラーを設定する部分を表示するために質問を編集できますか? –

+1

ハンドラとして 'static'メソッドを指定することはできません。 (とにかく意味をなさない;ハンドラはUIコンポーネントのプロパティであり、必ずコントローラ*インスタンス*のプロパティです。) –

答えて

1

は、代わりにこれを試してみてください:

は、メソッドに@FXMLを追加します。例:

@FXML public void changeStyle(){ 
.... 
.... 
.... 
} 
関連する問題