I have a JavaFX project that i develop with IntelliJ and when i run the program from there everythin works fine.
But when i run mvn clean package and try to run the jar that is built i get the following Exception:
Exception in thread "JavaFX Application Thread" java.lang.NullPointerException
at de.application.component.main.FilterListCell.setParent(FilterListCell.java:212)
at de.application.controller.MainController.lambda$initialize$2(MainController.java:183)
at javafx.scene.control.skin.ListViewSkin.createCell(ListViewSkin.java:432)
at javafx.scene.control.skin.ListViewSkin.lambda$new$9(ListViewSkin.java:207)
at javafx.scene.control.skin.VirtualFlow.getCell(VirtualFlow.java:1672)
at javafx.scene.control.skin.VirtualFlow.getCellLength(VirtualFlow.java:1801)
at javafx.scene.control.skin.VirtualFlow.computeViewportOffset(VirtualFlow.java:2639)
at javafx.scene.control.skin.VirtualFlow.layoutChildren(VirtualFlow.java:1245)
at javafx.scene.Parent.layout(Parent.java:1204)
at javafx.scene.Parent.layout(Parent.java:1211)
at javafx.scene.Parent.layout(Parent.java:1211)
at javafx.scene.Parent.layout(Parent.java:1211)
at javafx.scene.Parent.layout(Parent.java:1211)
at javafx.scene.Parent.layout(Parent.java:1211)
at javafx.scene.Parent.layout(Parent.java:1211)
at javafx.scene.Parent.layout(Parent.java:1211)
at javafx.scene.Parent.layout(Parent.java:1211)
at javafx.scene.Parent.layout(Parent.java:1211)
at javafx.scene.Parent.layout(Parent.java:1211)
at javafx.scene.Parent.layout(Parent.java:1211)
at javafx.scene.Scene.doLayoutPass(Scene.java:576)
at javafx.scene.Scene$ScenePulseListener.pulse(Scene.java:2482)
at com.sun.javafx.tk.Toolkit.lambda$runPulse$2(Toolkit.java:412)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.tk.Toolkit.runPulse(Toolkit.java:411)
at com.sun.javafx.tk.Toolkit.firePulse(Toolkit.java:438)
at com.sun.javafx.tk.quantum.QuantumToolkit.pulse(QuantumToolkit.java:519)
at com.sun.javafx.tk.quantum.QuantumToolkit.pulse(QuantumToolkit.java:499)
at com.sun.javafx.tk.quantum.QuantumToolkit.pulseFromQueue(QuantumToolkit.java:492)
at com.sun.javafx.tk.quantum.QuantumToolkit.lambda$runToolkit$11(QuantumToolkit.java:320)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:174)
at java.base/java.lang.Thread.run(Thread.java:834)
This is the line that fails:
public void setParent(ListView<CompositeFilter> parent) {
this.parent = parent;
root.prefWidthProperty().bind(parent.widthProperty().subtract(16)); // this fails
}
root is being null what I don't understand because I declare it in the controler like this
@FXML
public AnchorPane root;
and this is the fxml file:
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.geometry.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<AnchorPane fx:id="root" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity"
minWidth="-Infinity" prefHeight="200.0" xmlns="http://javafx.com/javafx/11.0.1"
xmlns:fx="http://javafx.com/fxml/1"
fx:controller="de.application.component.main.FilterListCell">
<HBox alignment="CENTER_LEFT" AnchorPane.leftAnchor="8.0" AnchorPane.topAnchor="8.0" AnchorPane.rightAnchor="8.0">
<!-- some content -->
</HBox>
</AnchorPane>
I have no idea why this is the case, i checked that IntelliJ uses the same JDK as i do.
Maybe this is an issue with my pom?
Here it is:
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.7.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>de.group</groupId>
<artifactId>application</artifactId>
<version>0.1-SNAPSHOT</version>
<properties>
<java.version>11</java.version>
<javafx.version>11.0.2</javafx.version>
<maven.compiler.plugin.version>3.8.1</maven.compiler.plugin.version>
</properties>
<dependencies>
<!-- JavaFX -->
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>${javafx.version}</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-fxml</artifactId>
<version>${javafx.version}</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-graphics</artifactId>
<version>${javafx.version}</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-base</artifactId>
<version>${javafx.version}</version>
</dependency>
<dependency>
<groupId>org.controlsfx</groupId>
<artifactId>controlsfx</artifactId>
<version>11.0.1</version>
</dependency>
<!-- Spring Boot -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
</dependency>
<!-- Other -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.module</groupId>
<artifactId>jackson-module-parameter-names</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jdk8</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jsr310</artifactId>
</dependency>
<dependency>
<groupId>net.rgielen</groupId>
<artifactId>javafx-weaver-spring</artifactId>
<version>1.2.0</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
<!-- Test -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven.compiler.plugin.version}</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
All help will be greatly appreciated.
EDIT
The code snippet from the MainController is this
lstFilter.setCellFactory(compositeFilterListView -> {
FxControllerAndView<FilterListCell, Node> cell = fxWeaver.load(FilterListCell.class);
if(cell.getView().isPresent()) {
cell.getView().get().setVisible(false);
cell.getController().setGraphic(cell.getView().get());
}
cell.getController().setParent(lstFilter); // setParent fails
return cell.getController();
});
This is just a CellFactory for the Listview lstFilter.
The real problem is the discrepency between running through Intellij, where this error does not occur and running the built jar trough the command line, where this fails.