- edited description
java.lang.NullPointerException: Cannot invoke "java.net.URL.openStream()" because the return value of "java.lang.Class.getResource(String)" is null
Hello,
I just tried to use this library. I took a look at the Demo app and tried to invoke FontAwesomeIconFactory.get()
in a similar fashion.
However, this call causes the following exception for me:
java.lang.reflect.InvocationTargetException
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:64)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:564)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:464)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:363)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:64)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:564)
at java.base/sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:1071)
Caused by: java.lang.RuntimeException: Exception in Application start method
at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:900)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication$2(LauncherImpl.java:195)
at java.base/java.lang.Thread.run(Thread.java:832)
Caused by: java.lang.RuntimeException: java.lang.NullPointerException: Cannot invoke "java.net.URL.openStream()" because the return value of "java.lang.Class.getResource(String)" is null
at de.jensd.fx.fontawesomefx.commons/de.jensd.fx.glyphs.GlyphsFactory.loadFont(GlyphsFactory.java:64)
at de.jensd.fx.fontawesomefx.commons/de.jensd.fx.glyphs.GlyphsFactory.<init>(GlyphsFactory.java:38)
at de.jensd.fx.fontawesomefx.fontawesome/de.jensd.fx.glyphs.fontawesome.utils.FontAwesomeIconFactory.<init>(FontAwesomeIconFactory.java:28)
at de.jensd.fx.fontawesomefx.fontawesome/de.jensd.fx.glyphs.fontawesome.utils.FontAwesomeIconFactory.get(FontAwesomeIconFactory.java:33)
Caused by: java.lang.NullPointerException: Cannot invoke "java.net.URL.openStream()" because the return value of "java.lang.Class.getResource(String)" is null
at de.jensd.fx.fontawesomefx.commons/de.jensd.fx.glyphs.GlyphsFactory.loadFont(GlyphsFactory.java:62)
... 17 more
This is the dependency I included (I had to exclude javafx dependencies, to prevent a conflict with my own dependencies)
<dependency>
<groupId>de.jensd</groupId>
<artifactId>fontawesomefx-fontawesome</artifactId>
<version>4.7.0-11</version>
<exclusions>
<exclusion>
<groupId>org.openjfx</groupId>
<artifactId>javafx-base</artifactId>
</exclusion>
<exclusion>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
</exclusion>
<exclusion>
<groupId>org.openjfx</groupId>
<artifactId>javafx-graphics</artifactId>
</exclusion>
</exclusions>
</dependency>
Afaik this is version 11.0, however, I was only able to select 9.0 here.
Kind Regards,
NeunEinser
Comments (2)
-
Account Deleted reporter -
The solution is to change the offending line
Font.loadFont(GlyphsFactory.class.getResource(pathToIconFont).openStream(), 10.0D);
toFont.loadFont(GlyphsFactory.class.getResourceAsStream(pathToIconFont), 10.0D);
How to go about patching the library is another issue.
See more: https://stackoverflow.com/q/54021754 and https://stackoverflow.com/q/65374578
- Log in to comment