Java8 ArchLinux arm 字体 NullPointerException

Java8 ArchLinux arm font NullPointerException

您好,我有一个基于 java 的 swing 应用程序,它在我的计算机上 运行 在 kali 发行版

中运行良好

我想 运行 这个应用程序 jar 在我的基于 ArchLinux 的 raspBerry pi3 b+ 中,我成功安装了 os 支持 LXDE,我也在使用 openjdk 完全支持 1 8 171

当运行使用commande java -jar dvr.jar时,我正面临一个从字体管理器引发的NullPointerException

java.lang.NullPointerException
    at sun.awt.FontConfiguration.getVersion(FontConfiguration.java:1264)
    at sun.awt.FontConfiguration.readFontConfigFile(FontConfiguration.java:219)
    at sun.awt.FontConfiguration.init(FontConfiguration.java:107)
    at sun.awt.X11FontManager.createFontConfiguration(X11FontManager.java:774)
    at sun.font.SunFontManager.run(SunFontManager.java:431)
    at java.security.AccessController.doPrivileged(Native Method)
    at sun.font.SunFontManager.<init>(SunFontManager.java:376)
    at sun.awt.FcFontManager.<init>(FcFontManager.java:35)
    at sun.awt.X11FontManager.<init>(X11FontManager.java:57)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
    at java.lang.Class.newInstance(Class.java:442)
    at sun.font.FontManagerFactory.run(FontManagerFactory.java:83)
    at java.security.AccessController.doPrivileged(Native Method)
    at sun.font.FontManagerFactory.getInstance(FontManagerFactory.java:74)
    at sun.font.SunFontManager.getInstance(SunFontManager.java:250)
    at sun.font.FontDesignMetrics.getMetrics(FontDesignMetrics.java:264)
    at sun.swing.SwingUtilities2.getFontMetrics(SwingUtilities2.java:1113)
    at javax.swing.JComponent.getFontMetrics(JComponent.java:1626)
    at javax.swing.plaf.basic.BasicLabelUI.getPreferredSize(BasicLabelUI.java:245)
    at javax.swing.JComponent.getPreferredSize(JComponent.java:1662)
    at javax.swing.tree.DefaultTreeCellRenderer.getPreferredSize(DefaultTreeCellRenderer.java:565)
    at javax.swing.plaf.basic.BasicTreeUI$NodeDimensionsHandler.getNodeDimensions(BasicTreeUI.java:2815)
    at javax.swing.tree.AbstractLayoutCache.getNodeDimensions(AbstractLayoutCache.java:492)
    at javax.swing.tree.VariableHeightLayoutCache$TreeStateNode.updatePreferredSize(VariableHeightLayoutCache.java:1360)
    at javax.swing.tree.VariableHeightLayoutCache.rebuild(VariableHeightLayoutCache.java:738)
    at javax.swing.tree.VariableHeightLayoutCache.setModel(VariableHeightLayoutCache.java:109)
    at javax.swing.plaf.basic.BasicTreeUI.setModel(BasicTreeUI.java:412)
    at javax.swing.plaf.basic.BasicTreeUI$Handler.propertyChange(BasicTreeUI.java:3414)
    at java.beans.PropertyChangeSupport.fire(PropertyChangeSupport.java:335)
    at java.beans.PropertyChangeSupport.firePropertyChange(PropertyChangeSupport.java:327)
    at java.beans.PropertyChangeSupport.firePropertyChange(PropertyChangeSupport.java:263)
    at java.awt.Component.firePropertyChange(Component.java:8428)
    at javax.swing.JTree.setModel(JTree.java:882)
    at javax.swing.JTree.<init>(JTree.java:670)
    at javax.swing.JTree.<init>(JTree.java:645)
    at javax.swing.JTree.<init>(JTree.java:629)
    at com.wanasis.vlc.view.JCheckBoxDragableTree.<init>(JCheckBoxDragableTree.java:88)
    at com.wanasis.vlc.view.JCheckBoxDragableTree.<init>(JCheckBoxDragableTree.java:72)
    at com.wanasis.vlc.control.MainFrameBuilder.build(MainFrameBuilder.java:27)
    at com.wanasis.vlc.SwingMain.run(SwingMain.java:56)
    at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:311)
    at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:758)
    at java.awt.EventQueue.access0(EventQueue.java:97)
    at java.awt.EventQueue.run(EventQueue.java:709)
    at java.awt.EventQueue.run(EventQueue.java:703)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:80)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:728)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:205)
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)

如何设置 swing LAF 使用系统当前字体?

我试过了但是没有结果

UIManager.setLookAndFeel(
    UIManager.getSystemLookAndFeelClassName());
UIManager.getLookAndFeelDefaults()
.put("defaultFont", new Font("Arial", Font.BOLD, 14));

归功于 – @Sergiy Medvynskyy -

我使用 java 字体部分来了解这个想法

我使用 pacman 工具搜索了一些字体 pacman -Ss font 然后我用谷歌搜索了它们并选择了一个我想要的字体包并将我的应用程序切换为使用 Times 字体

注意:不要忘记通过 -Sy pacman -Sy 更新 pacman,-Ss 是一个包搜索工具,在存储库 / 之后使用包的名称,例如 extra/mypack-alpha v.x.y.z 安装 mypack-alpha 使用 pacman -S mypack-alpha