sun.awt.X11FontManager: java.lang.reflect.InvocationTargetException (Arch Linux)

1.9k Views Asked by At

I have a kiosk program which writes some text on the screen. It is working fine on my Ubuntu 18 laptop and on a Raspberry Pi 3b running Raspbian. For minimal overhead, I'm using Arch Linux on a Raspberry Pi 3b running only X.org (+ xterm) to launch my program. But it fails without any usable information:

java.io.IOException: Problem reading font data.
at java.desktop/java.awt.Font.createFont0(Font.java:1177)
at java.desktop/java.awt.Font.createFont(Font.java:1046)
at code.Frame.(Frame.java:146)
at code.Main.main(Main.java:58)

The machine is running jre-openjdk 13 and the font is loaded from the JAR.

I have already tried to change java.io.tmpdir, to a definitely writable directory. I've also lowercased all files.

The basic structure is:

  • code
    • Main
    • Frame
  • resources
    • roboto_bold.ttf

And this is my code:

Font.createFont(Font.TRUETYPE_FONT, Main.class.getResourceAsStream("/resources/roboto_bold.ttf"))

Any idea what the issue is or how I can debug this?

UPDATE:

I have started debugging the call remotely using IntelliJ. This way I was able to create a stacktrace:

java.lang.reflect.InvocationTargetException
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:500)
at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:481)
at java.desktop/sun.font.FontManagerFactory$1.run(FontManagerFactory.java:84)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:312)
at java.desktop/sun.font.FontManagerFactory.getInstance(FontManagerFactory.java:74)
at java.desktop/java.awt.Font.createFont0(Font.java:1139)
at java.desktop/java.awt.Font.createFont(Font.java:1046)
at code.Frame.(Frame.java:146)
at code.Main.main(Main.java:58)

I think this means sun.awt.X11FontManager isn't present. I do not know how to fix that though. Seems like a dependency issue, but extra/fontconfig 2:2.13.91 and extra/freetype2 2.10.1 are installed.

1

There are 1 best solutions below

4
MadaManu On

You'd need a structure like:

src:
   com.company
     Main.java
   resources
     roboto_bold.ttf