添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
相关文章推荐
奋斗的皮蛋  ·  minio快速入门 - 掘金·  1 年前    · 
英俊的海龟  ·  Workbook.XmlImport 方法 ...·  1 年前    · 
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

Android - java.lang.NoClassDefFoundError: Failed resolution of: Lorg/slf4j/LoggerFactory;

Ask Question

As you can see, slf4j-android-1.7.25.jar in there. I also tried latest slf4j-android-1.7.30.jar, still having this issue.

Basically, I am trying to convert MS WORD file to pdf and here's the code I am trying which I found somewhere:

public static void docToPdf(InputStream is, String outputPath){       
    WordprocessingMLPackage wordMLPackage = null;
    try {
        wordMLPackage = WordprocessingMLPackage.load(is);
    } catch (Docx4JException e) {
        e.printStackTrace();
    List sections = wordMLPackage.getDocumentModel().getSections();
    for (int i = 0; i < sections.size(); i++) {
        wordMLPackage.getDocumentModel().getSections().get(i)
                .getPageDimensions();
    Mapper fontMapper = new IdentityPlusMapper();
    PhysicalFont font = PhysicalFonts.getPhysicalFonts().get(
            "Comic Sans MS");//set your desired font
    fontMapper.getFontMappings().put("Algerian", font);
    try {
        wordMLPackage.setFontMapper(fontMapper);
    } catch (Exception e) {
        e.printStackTrace();
   /* PdfSettings pdfSettings = new PdfSettings();
    org.docx4j.convert.out.pdf.PdfConversion conversion = new org.docx4j.convert.out.pdf.viaXSLFO.Conversion(
            wordMLPackage);
    //To turn off logger
    List<Logger> loggers = Collections.<Logger> list(LogManager. getCurrentLoggers());
    loggers.add(LogManager.getRootLogger());
    for (Logger logger : loggers) {
        logger.setLevel(Level.OFF);
    OutputStream out = null;
    try {
        out = new FileOutputStream(new File(outputPath));
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    /*conversion.output(out, pdfSettings);*/
    try {
        Docx4J.toPDF(wordMLPackage, out);
    } catch (Docx4JException e) {
        e.printStackTrace();
    System.out.println("DONE!!");

Further down in console, I can see another error message:

Caused by: java.lang.ClassNotFoundException: Didn't find class "org.slf4j.LoggerFactory" on path: DexPathList[[zip file "/system/framework/org.apache.http.legacy.boot.jar", ...

You need to add slf4j-api-1.7.30.jar in lib folder. As org.slf4j.LoggerFactory class is available in slf4j-api.jar.

Download the latest jar file from SLF4J distribution.

thanks, including this api jar does resolve this issue, but this line seems not load successfully at all: wordMLPackage = WordprocessingMLPackage.load(is); Also tried to pass a File instance, either case, a NULL is returned. – Shawn Apr 6, 2020 at 16:45

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.