2

Crossposted: • https://community.oracle.com/message/13857396#13857396http://www.coderanch.com/t/666195/JavaFX/java/FXML-JavaFX-app-run-JNLP#3105294

I try to deploy JavaFX FXML app as Web Start but I have got exception bellow. Jar is normaly working and also works deployed as self-contained app. I have build project in NetBeans v. 8.0.2. I have found so many similar threads over internet but either solution works nor I was thinking that solution is the right one.

In all solution has been identified this row

SomeClass root = FXMLLoader.load(getClass().getResource("someFXML.fxml"));

as a cause.

Solutions was:

  1. Use path /someFXML.fxml.
  2. Use FXMLLoader.load(getClass().getClassLoader().getResource("someFXML.fxml"));
  3. Use FXMLLoader.load(getClass().getClassLoader().getResource("packageName/someFXML.fxml"));
  4. Checks for files presence.
  5. Signing the jar.

I have tried perhaps all of them.

I am thinking that the solution not depends on row shown.

Exception

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

Main Class

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);
  }  
}

Controller

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>
Yarl
  • 728
  • 1
  • 7
  • 26
  • Include the output of `jar xvf ` in your question. Does it show `testfxmlpackage/FXMLDocument.fxml` exist? You might also be interested on some thoughts on [using JavaFX in a browser](http://stackoverflow.com/questions/19102000/javafx-can-it-really-be-deployed-in-a-browser). Also your stack trace has: `at xy.XY.start(XY.java:36)`. Are you sure that is the stack trace for the code you supplied? (You didn't supply an XY class in an xy package, so it is a bit weird). – jewelsea May 28 '16 at 08:50
  • I have the same problem , was there ever a resolution to this? – JavaHead Jun 13 '18 at 14:04

1 Answers1

0

I haven't tried it, but having a look at the source code I think an active SecurityManager might be the cause of the issue.

Possible solutions:

or

  • set the location property of the FXMLLoader. Please note that I've written some utility methods for FXMLLoader, which set the location property out-of-the-box: FXMLLoaders

The library is Open Source and can be use with the following dependency:

<dependency>
    <groupId>org.drombler.commons</groupId>
    <artifactId>drombler-commons-fx-core</artifactId>
    <version>0.7</version>
</dependency>
Puce
  • 37,247
  • 13
  • 80
  • 152