您现在的位置是:门户> 编程语言> Java

openjdk: easyexcle java.lang.NullPointerException: null at sun.awt.FontConfiguration.getVersion
x0ffer 2022-04-02 110人围观 0条评论
简介easy-excel生成错误,字体导致。easyexcle java.lang.NullPointerException: null at sun.awt.FontConfiguration.getVersion(FontConfiguration.java:1264) at sun.awt.FontConfiguration.readFontConfigFile(FontConfiguration.java:219)

    本地运行正常,部署到服务器异常。

    本地win10,jdk 1.8,服务器是docker上的,open jdk 1.8

    java.lang.NullPointerException: null
    at sun.awt.FontConfiguration.getVersion(FontConfiguration.java:1264) ~[?:1.8.0_151]
    at sun.awt.FontConfiguration.readFontConfigFile(FontConfiguration.java:219) ~[?:1.8.0_151]
    at sun.awt.FontConfiguration.init(FontConfiguration.java:107) ~[?:1.8.0_151]
    at sun.awt.X11FontManager.createFontConfiguration(X11FontManager.java:774) ~[?:1.8.0_151]
    at sun.font.SunFontManager$2.run(SunFontManager.java:431) ~[?:1.8.0_151]
    at java.security.AccessController.doPrivileged(Native Method) ~[?:1.8.0_151]
    at sun.font.SunFontManager.(SunFontManager.java:376) ~[?:1.8.0_151]
    at sun.awt.FcFontManager.(FcFontManager.java:35) ~[?:1.8.0_151]
    at sun.awt.X11FontManager.(X11FontManager.java:57) ~[?:1.8.0_151]
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[?:1.8.0_151]
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) ~[?:1.8.0_151]
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[?:1.8.0_151]
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423) ~[?:1.8.0_151]
    at java.lang.Class.newInstance(Class.java:442) ~[?:1.8.0_151]
    at sun.font.FontManagerFactory$1.run(FontManagerFactory.java:83) ~[?:1.8.0_151]
    at java.security.AccessController.doPrivileged(Native Method) ~[?:1.8.0_151]
    at sun.font.FontManagerFactory.getInstance(FontManagerFactory.java:74) ~[?:1.8.0_151]
    at java.awt.Font.getFont2D(Font.java:491) ~[?:1.8.0_151]
    at java.awt.Font.canDisplayUpTo(Font.java:2060) ~[?:1.8.0_151]
    at java.awt.font.TextLayout.singleFont(TextLayout.java:470) ~[?:1.8.0_151]
    at java.awt.font.TextLayout.(TextLayout.java:531) ~[?:1.8.0_151]
    at org.apache.poi.ss.util.SheetUtil.getDefaultCharWidth(SheetUtil.java:274) ~[poi-3.16.jar!/:3.16]
    at org.apache.poi.xssf.streaming.AutoSizeColumnTracker.(AutoSizeColumnTracker.java:117) ~[poi-ooxml-3.16.jar!/:3.16]
    at org.apache.poi.xssf.streaming.SXSSFSheet.(SXSSFSheet.java:79) ~[poi-ooxml-3.16.jar!/:3.16]
    at org.apache.poi.xssf.streaming.SXSSFWorkbook.createAndRegisterSXSSFSheet(SXSSFWorkbook.java:652) ~[poi-ooxml-3.16.jar!/:3.16]
    at org.apache.poi.xssf.streaming.SXSSFWorkbook.createSheet(SXSSFWorkbook.java:673) ~[poi-ooxml-3.16.jar!/:3.16]
    at org.apache.poi.xssf.streaming.SXSSFWorkbook.createSheet(SXSSFWorkbook.java:89) ~[poi-ooxml-3.16.jar!/:3.16]
    at com.alibaba.excel.util.WorkBookUtil.createSheet(WorkBookUtil.java:51) ~[easyexcel-1.1.2-beta4.jar!/:?]
    at com.alibaba.excel.context.WriteContext.currentSheet(WriteContext.java:112) ~[easyexcel-1.1.2-beta4.jar!/:?]
    at com.alibaba.excel.write.ExcelBuilderImpl.addContent(ExcelBuilderImpl.java:69) ~[easyexcel-1.1.2-beta4.jar!/:?]
    at com.alibaba.excel.ExcelWriter.write1(ExcelWriter.java:106) ~[easyexcel-1.1.2-beta4.jar!/:?]

    主要原因时两个问题:

    1)openjdk不包括sum.awt 的字体控件;

    2)linux未安装有 fontconfig 和 ttf-dejavu字体

    centos下解决方法

    1、安装fontconfig: >yum install fontconfig ;

    2、下载字体包: https://sourceforge.net/projects/dejavu/

    3、上传字体至/usr/share/fonts 下,并解压;

         更新字体 > fc-cache --force

    4、重启java服务即可。

    docker下解决方法

    1.安装字体,alpine中缺少FontConfiguration,那么就考虑安装ttf-dejavu这个软件

       下载字体包: https://sourceforge.net/projects/dejavu/

    2.docker修改dockerfile添加

        RUN apk add --update font-adobe-100dpi ttf-dejavu fontconfig

    3.DejaVu Sans Mono命令形式:

       sudo apt-get install ttf-dejavu

分享:

文章评论

    • wxpython 学习笔记 第一天
    • python文本数据处理学习笔记详解