2016-05-29 54 views
-2

我在NETBEANS 7.3.1上用JAVAFx創建一個圖形界面,我遇到了問題;該堆棧跟蹤javafx錯誤:未指定頁面語言

Executing com.javafx.main.Main from C:\Users\Guillaume\Documents\NetBeansProjects4\JavaFXApplication1\dist\run1976733325\JavaFXApplication1.jar using platform C:\Program Files\Java\jdk1.7.0_80/bin/java 
Page language not specified. 
file:/C:/Users/Guillaume/Documents/NetBeansProjects4/JavaFXApplication1/dist/run1976733325/JavaFXApplication1.jar!/javafxapplication1/Sample.fxml:30 
    at javafx.fxml.FXMLLoader$Element.processEventHandlerAttributes(FXMLLoader.java:510) 
    at javafx.fxml.FXMLLoader$ValueElement.processEndElement(FXMLLoader.java:594) 
    at javafx.fxml.FXMLLoader.processEndElement(FXMLLoader.java:2472) 
    at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2177) 
    at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2069) 
    at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2830) 
    at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2809) 
    at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2795) 
    at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2782) 
    at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2771) 
    at javafxapplication1.JavaFXApplication1.start(JavaFXApplication1.java:21) 
    at com.sun.javafx.application.LauncherImpl$5.run(LauncherImpl.java:319) 
    at com.sun.javafx.application.PlatformImpl$5.run(PlatformImpl.java:219) 
    at com.sun.javafx.application.PlatformImpl$4$1.run(PlatformImpl.java:182) 
    at com.sun.javafx.application.PlatformImpl$4$1.run(PlatformImpl.java:179) 
    at java.security.AccessController.doPrivileged(Native Method) 
    at com.sun.javafx.application.PlatformImpl$4.run(PlatformImpl.java:179) 
    at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:76) 
    at com.sun.glass.ui.win.WinApplication._runLoop(Native Method) 
    at com.sun.glass.ui.win.WinApplication.access$100(WinApplication.java:17) 
    at com.sun.glass.ui.win.WinApplication$3$1.run(WinApplication.java:67) 
    at java.lang.Thread.run(Thread.java:745) 

Exception in Application start method 
java.lang.reflect.InvocationTargetException 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
    at java.lang.reflect.Method.invoke(Method.java:606) 
    at com.javafx.main.Main.launchApp(Main.java:698) 
    at com.javafx.main.Main.main(Main.java:871) 
Caused by: java.lang.RuntimeException: Exception in Application start method 
    at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:403) 
    at com.sun.javafx.application.LauncherImpl.access$000(LauncherImpl.java:47) 
    at com.sun.javafx.application.LauncherImpl$1.run(LauncherImpl.java:115) 
    at java.lang.Thread.run(Thread.java:745) 
Caused by: javafx.fxml.LoadException: Page language not specified. 
    at javafx.fxml.FXMLLoader$Element.processEventHandlerAttributes(FXMLLoader.java:510) 
    at javafx.fxml.FXMLLoader$ValueElement.processEndElement(FXMLLoader.java:594) 
    at javafx.fxml.FXMLLoader.processEndElement(FXMLLoader.java:2472) 
    at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2177) 
    at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2069) 
    at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2830) 
    at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2809) 
    at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2795) 
    at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2782) 
    at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2771) 
    at javafxapplication1.JavaFXApplication1.start(JavaFXApplication1.java:21) 
    at com.sun.javafx.application.LauncherImpl$5.run(LauncherImpl.java:319) 
    at com.sun.javafx.application.PlatformImpl$5.run(PlatformImpl.java:219) 
    at com.sun.javafx.application.PlatformImpl$4$1.run(PlatformImpl.java:182) 
    at com.sun.javafx.application.PlatformImpl$4$1.run(PlatformImpl.java:179) 
    at java.security.AccessController.doPrivileged(Native Method) 
    at com.sun.javafx.application.PlatformImpl$4.run(PlatformImpl.java:179) 
    at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:76) 
    at com.sun.glass.ui.win.WinApplication._runLoop(Native Method) 
    at com.sun.glass.ui.win.WinApplication.access$100(WinApplication.java:17) 
    at com.sun.glass.ui.win.WinApplication$3$1.run(WinApplication.java:67) 
    ... 1 more 
Java Result: 1 

的FXML文件是:

<?xml version="1.0" encoding="UTF-8"?> 

<?import java.lang.*?> 
<?import java.util.*?> 
<?import javafx.collections.*?> 
<?import javafx.scene.*?> 
<?import javafx.scene.control.*?> 
<?import javafx.scene.layout.*?> 

<AnchorPane id="AnchorPane" prefHeight="307.0" prefWidth="503.0" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/2.2"> 
    <children> 
    <Label id="lb_config" layoutX="14.0" layoutY="4.0" prefHeight="37.0" prefWidth="252.0" text="Configuration de compteurs SDM120" /> 
    <Label id="lb_select" layoutX="93.0" layoutY="70.0" text="Selection compteur adresse n°" /> 
    <Label id="lb_config_act" layoutX="82.0" layoutY="126.0" text="Configuration actuelle :" /> 
    <Label id="lb_vit" layoutX="93.0" layoutY="154.0" text="Vitesse de transmission" /> 
    <Label id="lb_tps" layoutX="208.0" layoutY="203.0" text="Temps" /> 
    <Label id="lb_imp" layoutX="134.0" layoutY="244.0" text="Sortie à impulsion" /> 
    <Button fx:id="bt_modif" layoutX="364.0" layoutY="273.0" mnemonicParsing="false" text="Modifier" /> 
    <TextField fx:id="tf_vit" layoutX="281.0" layoutY="154.0" prefWidth="200.0" /> 
    <TextField fx:id="tf_tps" layoutX="281.0" layoutY="203.0" prefWidth="200.0" /> 
    <TextField fx:id="tf_imp" layoutX="281.0" layoutY="241.0" prefWidth="200.0" /> 
    <ComboBox fx:id="me_sel" layoutX="298.0" layoutY="67.0" prefWidth="183.0" promptText="Adresse du compteur"> 
     <items> 
     <FXCollections fx:factory="observableArrayList"> 
      <String fx:value="Item 1" /> 
      <String fx:value="Item 2" /> 
     </FXCollections> 
     </items> 
    </ComboBox> 
    <Button fx:id="bt_visualiser" layoutX="357.0" layoutY="105.0" mnemonicParsing="false" onAction="buttonAction" text="Visualiser" /> 
    </children> 
</AnchorPane> 
+0

請編輯您的問題以包含代碼,而不是粘貼鏈接。 –

回答

3

您指定用於您有沒有上下文的所有按鈕的操作處理程序:

<Button ... onAction="buttonAction" ... /> 

根據可以將documentation事件處理程序指定爲控制器方法(最常用的方法)或使用腳本語言(罕見)。要使用控制器,您需要指定並實現一個控制器類,並將用#處理該事件的方法名稱作爲前綴。例如: -

package my.package ; 

public class MyControllerClass { 

    // ... 

    @FXML 
    private void buttonAction() { 
     // code to execute when button is fired 
    } 
} 

,然後在FXML做:

<AnchorPane id="AnchorPane" prefHeight="307.0" prefWidth="503.0" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/2.2" 
    fx:controller="my.package.MyControllerClass"> 

    <!-- ... --> 

    <Button ... onAction="#buttonAction" ... /> 

    <!-- ... --> 
</AnchorPane> 

如果onAction屬性不#開始,它被解釋爲腳本代碼。這是處理事件的一種非常不常見的方式。對於這個工作,你必須在FXML前導的language指令,以及onAction屬性的內容必須是有效的腳本代碼:

<?language javascript?> 

<!-- imports etc --> 

<AnchorPane id="AnchorPane" prefHeight="307.0" prefWidth="503.0" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/2.2"> 

    <!-- ... --> 

    <Button ... onAction="java.lang.System.out.println('You clicked me!');" ... /> 

    <!-- ... --> 
</AnchorPane> 

(你可以在其中定義功能<script>標籤,即可以從這個屬性,等等。再一次引用,請參閱文檔)。

在你的代碼,因爲onAction屬性不啓動#,則FXML解析器期待腳本代碼,但因爲你沒有language指令,它不能試圖解釋它;因此是例外。