Crossposted: •https://community.oracle.com/message/13857396#13857396 •http://www.coderanch.com/t/666195/JavaFX/java/FXML-JavaFX-app-run-JNLP#3105294
我尝试将JavaFX FXML应用程序部署为Web Start,但我有例外。 Jar正常工作,也可以作为独立应用程序部署。我在NetBeans v.8.0.2中构建了项目。我在互联网上找到了这么多类似的线程,但任何解决方案都有效,我也不认为解决方案是正确的。
在所有解决方案中都已确定此行
SomeClass root = FXMLLoader.load(getClass()。getResource(“someFXML.fxml”));
作为一个原因。
解决方案是:
我已经尝试了所有这些。
我认为解决方案不依赖于显示的行。
异常
java.lang.NullPointerException: Location is required.
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3207)
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 xy.XY.start(XY.java:36)
at com.sun.javafx.applet.FXApplet2$2.run(FXApplet2.java:134)
at com.sun.javafx.application.PlatformImpl.lambda$null$173 (PlatformImpl.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$174(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$148(WinApplication.java:191)
at java.lang.Thread.run(Unknown Source)
Exception in thread "JavaFX Application Thread" java.lang.RuntimeException: java.lang.NullPointerException: Location is required.
at com.sun.javafx.applet.FXApplet2$2.run(FXApplet2.java:150)
at com.sun.javafx.application.PlatformImpl.lambda$null$173 (PlatformImpl.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$174(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$148(WinApplication.java:191)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.NullPointerException: Location is required.
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3207)
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 xy.XY.start(XY.java:36)
at com.sun.javafx.applet.FXApplet2$2.run(FXApplet2.java:134)
... 7 more
主要类
package testfxmlpackage;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
public class TestFXMLPackage extends Application {
@Override
public void start(Stage stage) throws Exception {
Parent root = FXMLLoader.load(getClass().getResource("FXMLDocument.fxml"));
Scene scene = new Scene(root);
stage.setScene(scene);
stage.show();
}
public static void main(String[] args) {
launch(args);
}
}
控制器
package testfxmlpackage;
import javafx.fxml.FXML;
import javafx.scene.text.TextFlow;
public class FXMLDocumentController {
@FXML TextFlow xy;
}
FXML
<?xml version="1.0" encoding="UTF-8"?>
<?import java.lang.*?>
<?import java.util.*?>
<?import javafx.scene.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.text.TextFlow?>
<AnchorPane id="AnchorPane" prefHeight="200" prefWidth="320" xmlns:fx="http://javafx.com/fxml/1" fx:controller="testfxmlpackage.FXMLDocumentController">
<children>
<TextFlow fx:id="xy" layoutX="22.0" layoutY="234.0" prefHeight="74.0" prefWidth="433.0" style="-fx-border-color: ADD8E6;" AnchorPane.bottomAnchor="14.0" AnchorPane.leftAnchor="22.0" AnchorPane.rightAnchor="142.0" />
</children>
</AnchorPane>
答案 0 :(得分:0)
我没有尝试过,但看看source code我认为活动的SecurityManager可能是问题的原因。
可能的解决方案:
或
该库是开源的,可以使用以下依赖项:
<dependency>
<groupId>org.drombler.commons</groupId>
<artifactId>drombler-commons-fx-core</artifactId>
<version>0.7</version>
</dependency>