[alibaba/easyexcel]3.1.1 按照模板导出com.alibaba.excel.exception.ExcelGenerateException: java.lang.ExceptionInInitializerError

2024-05-09 203 views
4

我是在安卓中使用的,通过Debug查看后发现3.1.0和3.1.1版本的BeanMap都是使用org.springframework.cglib.beans.BeanMap里面的BeanMap,在3.1.0和3.1.1版本项目中没有使用这个com.alibaba.excel.support.cglib.beans.BeanMap,导致我无法应用在安卓中,希望可以更改一下这个依赖包

触发Bug的代码

   EasyExcel.write(fileName, History.class)
            .sheet("模板1")
            .doWrite(historyList);
实体类
 public class History {
    /**
     * 主键
     */
    @ExcelIgnore
    private Integer id;
    /**
     * 在/离线模式
     */
    @ExcelProperty(value = "在/离线模式")
    private Integer mode;
    /**
     * 扫码模式
     */
    @ExcelProperty(value = "扫码模式")
    private Integer code;

    public History() {

    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }
    public Integer getMode() {
        return mode;
    }

    public void setMode(Integer mode) {
        this.mode = mode;
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }
异常提示
E/WM-WorkerWrapper: Work [ id=26e7ed59-50fb-4c06-9d7f-4a918fedaac5, tags={ com.gzxn.pda.service.worker.ExportExcelWorker } ] failed because it threw an exception/error
    java.util.concurrent.ExecutionException: com.alibaba.excel.exception.ExcelGenerateException: java.lang.ExceptionInInitializerError
        at androidx.work.impl.utils.futures.AbstractFuture.getDoneValue(AbstractFuture.java:516)
        at androidx.work.impl.utils.futures.AbstractFuture.get(AbstractFuture.java:475)
        at androidx.work.impl.WorkerWrapper$2.run(WorkerWrapper.java:284)
        at androidx.work.impl.utils.SerialExecutor$Task.run(SerialExecutor.java:91)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
        at java.lang.Thread.run(Thread.java:919)
     Caused by: com.alibaba.excel.exception.ExcelGenerateException: java.lang.ExceptionInInitializerError
        at com.alibaba.excel.write.ExcelBuilderImpl.addContent(ExcelBuilderImpl.java:65)
        at com.alibaba.excel.ExcelWriter.write(ExcelWriter.java:70)
        at com.alibaba.excel.ExcelWriter.write(ExcelWriter.java:47)
        at com.alibaba.excel.write.builder.ExcelWriterSheetBuilder.doWrite(ExcelWriterSheetBuilder.java:62)
        at com.gzxn.pda.service.worker.ExportExcelWorker.doWork(ExportExcelWorker.java:90)
        at androidx.work.Worker$1.run(Worker.java:85)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167) 
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641) 
        at java.lang.Thread.run(Thread.java:919) 
     Caused by: java.lang.ExceptionInInitializerError
        at com.alibaba.excel.util.BeanMapUtils.create(BeanMapUtils.java:25)
        at com.alibaba.excel.write.executor.ExcelWriteAddExecutor.addJavaObjectToExcel(ExcelWriteAddExecutor.java:144)
        at com.alibaba.excel.write.executor.ExcelWriteAddExecutor.addOneRowOfDataToExcel(ExcelWriteAddExecutor.java:82)
        at com.alibaba.excel.write.executor.ExcelWriteAddExecutor.add(ExcelWriteAddExecutor.java:58)
        at com.alibaba.excel.write.ExcelBuilderImpl.addContent(ExcelBuilderImpl.java:59)
        at com.alibaba.excel.ExcelWriter.write(ExcelWriter.java:70) 
        at com.alibaba.excel.ExcelWriter.write(ExcelWriter.java:47) 
        at com.alibaba.excel.write.builder.ExcelWriterSheetBuilder.doWrite(ExcelWriterSheetBuilder.java:62) 
        at com.gzxn.pda.service.worker.ExportExcelWorker.doWork(ExportExcelWorker.java:90) 
        at androidx.work.Worker$1.run(Worker.java:85) 
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167) 
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641) 
        at java.lang.Thread.run(Thread.java:919) 
     Caused by: com.alibaba.excel.support.cglib.core.CodeGenerationException: java.lang.UnsupportedOperationException-->can't load this type of class file
        at com.alibaba.excel.support.cglib.core.ReflectUtils.defineClass(ReflectUtils.java:558)
        at com.alibaba.excel.support.cglib.core.AbstractClassGenerator.generate(AbstractClassGenerator.java:363)
        at com.alibaba.excel.support.cglib.core.AbstractClassGenerator$ClassLoaderData$3.apply(AbstractClassGenerator.java:110)
        at com.alibaba.excel.support.cglib.core.AbstractClassGenerator$ClassLoaderData$3.apply(AbstractClassGenerator.java:108)
        at com.alibaba.excel.support.cglib.core.internal.LoadingCache$2.call(LoadingCache.java:54)
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
        at com.alibaba.excel.support.cglib.core.internal.LoadingCache.createEntry(LoadingCache.java:61)
        at com.alibaba.excel.support.cglib.core.internal.LoadingCache.get(LoadingCache.java:34)
        at com.alibaba.excel.support.cglib.core.AbstractClassGenerator$ClassLoaderData.get(AbstractClassGenerator.java:134)
        at com.alibaba.excel.support.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:319)
        at com.alibaba.excel.support.cglib.core.KeyFactory$Generator.create(KeyFactory.java:237)
        at com.alibaba.excel.support.cglib.core.KeyFactory.create(KeyFactory.java:184)
        at com.alibaba.excel.support.cglib.core.KeyFactory.create(KeyFactory.java:164)
        at com.alibaba.excel.support.cglib.core.KeyFactory.create(KeyFactory.java:156)
        at com.alibaba.excel.support.cglib.beans.BeanMap$Generator.<clinit>(BeanMap.java:66)
        at com.alibaba.excel.util.BeanMapUtils.create(BeanMapUtils.java:25) 
        at com.alibaba.excel.write.executor.ExcelWriteAddExecutor.addJavaObjectToExcel(ExcelWriteAddExecutor.java:144) 
        at com.alibaba.excel.write.executor.ExcelWriteAddExecutor.addOneRowOfDataToExcel(ExcelWriteAddExecutor.java:82) 
        at com.alibaba.excel.write.executor.ExcelWriteAddExecutor.add(ExcelWriteAddExecutor.java:58) 
        at com.alibaba.excel.write.ExcelBuilderImpl.addContent(ExcelBuilderImpl.java:59) 
        at com.alibaba.excel.ExcelWriter.write(ExcelWriter.java:70) 
        at com.alibaba.excel.ExcelWriter.write(ExcelWriter.java:47) 
        at com.alibaba.excel.write.builder.ExcelWriterSheetBuilder.doWrite(ExcelWriterSheetBuilder.java:62) 
        at com.gzxn.pda.service.worker.ExportExcelWorker.doWork(ExportExcelWorker.java:90) 
        at androidx.work.Worker$1.run(Worker.java:85) 
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167) 
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641) 
        at java.lang.Thread.run(Thread.java:919) 
     Caused by: java.lang.UnsupportedOperationException: can't load this type of class file
        at java.lang.ClassLoader.defineClass(ClassLoader.java:591)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.alibaba.excel.support.cglib.core.ReflectUtils.defineClass(ReflectUtils.java:555)
        at com.alibaba.excel.support.cglib.core.AbstractClassGenerator.generate(AbstractClassGenerator.java:363) 
        at com.alibaba.excel.support.cglib.core.AbstractClassGenerator$ClassLoaderData$3.apply(AbstractClassGenerator.java:110) 
        at com.alibaba.excel.support.cglib.core.AbstractClassGenerator$ClassLoaderData$3.apply(AbstractClassGenerator.java:108) 
        at com.alibaba.excel.support.cglib.core.internal.LoadingCache$2.call(LoadingCache.java:54) 
        at java.util.concurrent.FutureTask.run(FutureTask.java:266) 
        at com.alibaba.excel.support.cglib.core.internal.LoadingCache.createEntry(LoadingCache.java:61) 
        at com.alibaba.excel.support.cglib.core.internal.LoadingCache.get(LoadingCache.java:34) 
        at com.alibaba.excel.support.cglib.core.AbstractClassGenerator$ClassLoaderData.get(AbstractClassGenerator.java:134) 
        at com.alibaba.excel.support.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:319) 
        at com.alibaba.excel.support.cglib.core.KeyFactory$Generator.create(KeyFactory.java:237) 
        at com.alibaba.excel.support.cglib.core.KeyFactory.create(KeyFactory.java:184) 
        at com.alibaba.excel.support.cglib.core.KeyFactory.create(KeyFactory.java:164) 
        at com.alibaba.excel.support.cglib.core.KeyFactory.create(KeyFactory.java:156) 
        at com.alibaba.excel.support.cglib.beans.BeanMap$Generator.<clinit>(BeanMap.java:66) 
        at com.alibaba.excel.util.BeanMapUtils.create(BeanMapUtils.java:25) 
        at com.alibaba.excel.write.executor.ExcelWriteAddExecutor.addJavaObjectToExcel(ExcelWriteAddExecutor.java:144) 
        at com.alibaba.excel.write.executor.ExcelWriteAddExecutor.addOneRowOfDataToExcel(ExcelWriteAddExecutor.java:82) 
        at com.alibaba.excel.write.executor.ExcelWriteAddExecutor.add(ExcelWriteAddExecutor.java:58) 
        at com.alibaba.excel.write.ExcelBuilderImpl.addContent(ExcelBuilderImpl.java:59) 
        at com.alibaba.excel.ExcelWriter.write(ExcelWriter.java:70) 
        at com.alibaba.excel.ExcelWriter.write(ExcelWriter.java:47) 
        at com.alibaba.excel.write.builder.ExcelWriterSheetBuilder.doWrite(ExcelWriterSheetBuilder.java:62) 
        at com.gzxn.pda.service.worker.ExportExcelWorker.doWork(ExportExcelWorker.java:90) 
        at androidx.work.Worker$1.run(Worker.java:85) 
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167) 
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641) 
        at java.lang.Thread.run(Thread.java:919) 
I/WM-WorkerWrapper: Worker result FAILURE for Work [ id=26e7ed59-50fb-4c06-9d7f-4a918fedaac5, tags={ com.gzxn.pda.service.worker.ExportExcelWorker } ]

image

image

提示的异常或者没有达到的效果

回答

6

填充的时候也有这个bug,获取相对路径文件的名称、路径、流都会报错

3

请问有解决办法了吗?

5

我手动写代码报了个awt相关的 Failed resolution of: Ljava/awt/font/FontRenderContext;,这个awt在andoid上又不支持,请问有大佬懂吗?

6

我手动写代码报了个awt相关的 Failed resolution of: Ljava/awt/font/FontRenderContext;,这个awt在andoid上又不支持,请问有大佬懂吗?

引入部分awt图形库代码之后报了这个,还要awt.so包,,无解了 image

8

我手动写代码报了个awt相关的 Failed resolution of: Ljava/awt/font/FontRenderContext;,这个awt在andoid上又不支持,请问有大佬懂吗?

引入部分awt图形库代码之后报了这个,还要awt.so包,,无解了 image

这里有个poi的安卓库可以试试(poi-android),至少比使用jxl的内存问题好点,如果easyexcel能屏蔽掉poi部分api不能在androidSdk的感觉也挺好用的,毕竟有中文文档==,

0

@gzxn @xuexixuexijpg @kaTelance 你们都是搞安卓的么? 是的化麻烦加下钉钉下,联系下群主 可以一起把安卓支持了