如何修复线程中的此异常";“主要”;java.lang.NoSuchMethodError:org.apache.poi.POIXMLDocumentPart.getPackageRelationship

如何修复线程中的此异常";“主要”;java.lang.NoSuchMethodError:org.apache.poi.POIXMLDocumentPart.getPackageRelationship,java,pdf,apache-poi,Java,Pdf,Apache Poi,我的要求是创建一个java代码,将现有的docx转换为具有适当格式和对齐方式的pdf 快速谷歌的标题给了我这个(仍然开放)的问题 最后一条评论说 khausam在3月12日发表评论时使用了:compile group: “fr.opensagres.xdocreport”,名称: 'org.apache.poi.xwpf.converter.xhtml',版本:'1.0.6' 我切换到:编译组:“fr.opensagres.xdocreport”,名称: “fr.opensagres.poi.

我的要求是创建一个java代码,将现有的docx转换为具有适当格式和对齐方式的pdf


快速谷歌的标题给了我这个(仍然开放)的问题

最后一条评论说

khausam在3月12日发表评论时使用了:compile group: “fr.opensagres.xdocreport”,名称: 'org.apache.poi.xwpf.converter.xhtml',版本:'1.0.6'

我切换到:编译组:“fr.opensagres.xdocreport”,名称: “fr.opensagres.poi.xwpf.converter.xhtml”,版本:“2.0.1”

问题解决了。有人能确认这是否是一个错误吗 合理可行的升级路径


你把这个方法称为哪里?@XtremeBaumer,显然这是从库代码中抛出的。我把poi库的版本从poi 3.17改为poi 3.15。问题解决了。
public class CreatePdf {

    public static void main(String[] args) {
        CreatePdf pdf = new CreatePdf();
        System.out.println("start");
        pdf.ConvertToPDF("D:\\doctopdf.docx", "D:\\Test1.pdf");
    }

    public void ConvertToPDF(String docPath, String pdfPath) {

        try {
            InputStream doc = new FileInputStream(new File(docPath));
            XWPFDocument document = new XWPFDocument(doc);
            PdfOptions options = PdfOptions.create();
            OutputStream out = new FileOutputStream(new File(pdfPath));
            PdfConverter.getInstance().convert(document, out, options);
            System.out.print("Done");
      /*}catch(FileNotFoundException ex){
            System.out.print(ex.getMessage());*/
        }catch(IOException ex){
            System.out.print(ex.getMessage());
        }
    }   
}