Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/369.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何将外部JS脚本导入FXML布局?_Java_Javascript_Javafx 2_Javafx_Fxml - Fatal编程技术网

Java 如何将外部JS脚本导入FXML布局?

Java 如何将外部JS脚本导入FXML布局?,java,javascript,javafx-2,javafx,fxml,Java,Javascript,Javafx 2,Javafx,Fxml,我有FXML布局,我想添加外部JS文件,比如src=http://blablabla.org/bla.js 在HTTP中,我尝试了以下内容: <?xml version="1.0" encoding="UTF-8"?> <?language javascript?> <?import java.lang.*?> <?import javafx.scene.*?> <?import javafx.scene.control.*?> &l

我有FXML布局,我想添加外部JS文件,比如src=http://blablabla.org/bla.js 在HTTP中,我尝试了以下内容:

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

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

<AnchorPane id="AnchorPane" prefHeight="200" prefWidth="320" xmlns:fx="http://javafx.com/fxml">
<children>
    <Button id="button" layoutX="126" layoutY="90" text="Click Me!" fx:id="button"
            onAction="changeButtonLabel(event);"/>
    <Label id="label" layoutX="126" layoutY="120" minHeight="16" minWidth="69" prefHeight="16" prefWidth="69"
           fx:id="label"/>
</children>

<fx:script source="http://localhost:8080/TestApplication/main_script.js"/>

<stylesheets>
    <String fx:value="hive://localhost:8080/TestApplication/main.css" />
</stylesheets>
</AnchorPane>

我的代码有什么问题?

错误消息是基本位置未定义。我建议在url之前添加一个@,并将javascript放在与代码相关的路径中,例如@scripts/main_script.js,其中scripts是Java代码所在的目录

javafx.fxml.LoadException: javafx.fxml.LoadException: Base location is undefined.
at javafx.fxml.FXMLLoader$ScriptElement.processStartElement(FXMLLoader.java:1332)
at javafx.fxml.FXMLLoader.processStartElement(FXMLLoader.java:2314)
at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2131)
at org.hive.browser.BrowserController$2.run(BrowserController.java:65)
Caused by: javafx.fxml.LoadException: Base location is undefined.
at javafx.fxml.FXMLLoader$ScriptElement.processStartElement(FXMLLoader.java:1314)
... 3 more
Exception in runnable
java.lang.NullPointerException: Children: child node is null: parent = Pane[id=contentPane]
at javafx.scene.Parent$1.onProposedChange(Parent.java:316)
at com.sun.javafx.collections.VetoableObservableList.add(VetoableObservableList.java:165)
at com.sun.javafx.collections.ObservableListWrapper.add(ObservableListWrapper.java:144)
at org.hive.browser.BrowserController$2$1.run(BrowserController.java:80)
at com.sun.javafx.application.PlatformImpl$4$1.run(PlatformImpl.java:179)
at com.sun.javafx.application.PlatformImpl$4$1.run(PlatformImpl.java:176)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl$4.run(PlatformImpl.java:176)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:76)