Android - java.lang.NoClassDefFoundError: Failed resolution of: Lorg/slf4j/LoggerFactory;
Android - java.lang.NoClassDefFoundError: Failed resolution of: Lorg/slf4j/LoggerFactory;
我已经针对此 运行 时间错误进行了一些搜索:
java.lang.NoClassDefFoundError: Failed resolution of: Lorg/slf4j/LoggerFactory
这是我的 Android 项目中的 "libs":
如你所见,slf4j-android-1.7.25.jar 在那里。我也尝试了最新的 slf4j-android-1.7.30.jar,仍然有这个问题。
基本上,我正在尝试将 MS WORD 文件转换为 pdf,这是我在某处找到的正在尝试的代码:
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!!");
}
在控制台的下方,我可以看到另一条错误消息:
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", ...
您需要在 lib 文件夹中添加 slf4j-api-1.7.30.jar
。作为 org.slf4j.LoggerFactory class 在 slf4j-api.jar.
中可用
从SLF4J distribution下载最新的jar文件。
我已经针对此 运行 时间错误进行了一些搜索:
java.lang.NoClassDefFoundError: Failed resolution of: Lorg/slf4j/LoggerFactory
这是我的 Android 项目中的 "libs":
如你所见,slf4j-android-1.7.25.jar 在那里。我也尝试了最新的 slf4j-android-1.7.30.jar,仍然有这个问题。
基本上,我正在尝试将 MS WORD 文件转换为 pdf,这是我在某处找到的正在尝试的代码:
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!!");
}
在控制台的下方,我可以看到另一条错误消息:
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", ...
您需要在 lib 文件夹中添加 slf4j-api-1.7.30.jar
。作为 org.slf4j.LoggerFactory class 在 slf4j-api.jar.
从SLF4J distribution下载最新的jar文件。