gpt4 book ai didi

java.lang.NoSuchMethodError : org. apache.poi.util.POILogger.log(ILjava/lang/Object;Ljava/lang/Throwable;)V

转载 作者:行者123 更新时间:2023-12-02 01:06:57 24 4
gpt4 key购买 nike

您好,我第一次尝试使用 apache.poi 将 xlsx 转换为 pdf,它工作得很好,直到我添加一些需要使用 3.17 版本的代码(将 docx 转换为 pdf)。之后,当我尝试转换 xlsx 时,出现此错误

java.lang.NoSuchMethodError: org.apache.poi.util.POILogger.log(ILjava/lang/Object;Ljava/lang/Throwable;)V

我不知道会发生什么。无论如何,这是我获取文件的一些代码

ByteArrayOutputStream baos = new ByteArrayOutputStream();
OPCPackage pkg = OPCPackage.open(file);
XSSFWorkbook xls = new XSSFWorkbook(pkg);
XSSFSheet worksheet = xls.getSheetAt(0);

OPCPackage 打开文件(InputStream)时出现错误。请问有人可以帮助我吗?

库:poi 3.17 和所有依赖项,itextpdf 5.5.13

最佳答案

请检查您的依赖项的实际版本(例如使用 mvn dependency:tree)。

我认为 poi 3.17 和 itextpdf 5.5.13 没有任何问题。下面pom的单元测试通过了。

package stackoverflow.q59892610;

import org.junit.Rule;
import org.junit.Test;

import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.junit.rules.TemporaryFolder;

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStream;
import java.util.UUID;

import static org.apache.poi.xssf.usermodel.XSSFWorkbookType.XLSX;
import static org.junit.Assert.*;

public class PoiTest
{
@Rule
public TemporaryFolder folder= new TemporaryFolder(new File("target"));
@Test
public void xlsTest() throws Exception
{
File file = new File(folder.getRoot(), UUID.randomUUID() + ".xlxs");
String cellValue = UUID.randomUUID().toString();
try (XSSFWorkbook xls = new XSSFWorkbook(XLSX)) {
xls.createSheet("new sheet").createRow(0).createCell(0).setCellValue(cellValue);
try(OutputStream out = new FileOutputStream(file)) {xls.write(out);}
}
ByteArrayOutputStream baos = new ByteArrayOutputStream();
XSSFWorkbook xls = new XSSFWorkbook(file);
XSSFSheet worksheet = xls.getSheetAt(0);
assertEquals("cell value mismatch", cellValue, worksheet.getRow(0).getCell(0).getStringCellValue());
}
}
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>stackoverflow</groupId>
<artifactId>poi-logger</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>poi-logger</name>
<url>http://maven.apache.org</url>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<poi-version>3.17</poi-version>
<itextpdf-version>5.5.13</itextpdf-version>
<junit-version>4.13</junit-version>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit-version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>${poi-version}</version>
</dependency>
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>itextpdf</artifactId>
<version>${itextpdf-version}</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>${poi-version}</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
</project>

关于java.lang.NoSuchMethodError : org. apache.poi.util.POILogger.log(ILjava/lang/Object;Ljava/lang/Throwable;)V,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59892610/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com