如何使用POI为DOC文件时,解决的NoSuchMethodError [英] How to solve a NoSuchMethodError when using POI for doc files
问题描述
当我想实现的任何code以下
When I was trying to implement any code of the following
File someFile = new File("D:\\arz.doc");
InputStream inputStrm = new FileInputStream(someFile);
HWPFDocument wordDoc = new HWPFDocument(inputStrm);
System.out.println(wordDoc.getText());
或
POIFSFileSystem fs = new POIFSFileSystem(new FileInputStream("D:\\arz.doc"));
WordExtractor extractor = new WordExtractor(fs);
String wordText = extractor.getText();
,错误消息永远是如下:
, the error message always comes out as following:
Exception in thread "main" java.lang.NoSuchMethodError:
org.apache.poi.poifs.filesystem.POIFSFileSystem.getRoot()Lorg/apache/poi/poifs/filesystem/DirectoryNode;
at org.apache.poi.hwpf.HWPFDocument.(HWPFDocument.java:186)
at DB_connect.dissertation_araalz.ParseWodDocFile.main(ParseWodDocFile.java:29)
Java Result: 1
BUILD SUCCESSFUL (total time: 3 seconds)
能否请你帮我这个问题?
Could you please help me in that problem?
推荐答案
您几乎肯定会对你的classpath POI的两个副本。一个是包含要使用该功能的新的,最新的版本。另一种是较旧的版本,不支持,似乎你的系统是preferring,哥哥...
You almost certainly have two copies of POI on your classpath. One is the new, latest version which contains the feature you want to use. The other is an older version that doesn't, and it seems your system is preferring the older one...
这是一个常见的问题,足以使 POI FAQ涵盖了这个非常情况下。理想的情况下,就看您的类路径,并尝试找出多余的旧的POI罐子。但是,如果还是不行,请尝试从POI FAQ code这个片断:
This is a common enough problem that the POI FAQ Covers this very case. Ideally, just look at your classpath, and try to identify the extra older POI jar. However, if that doesn't work, try this snippet of code from the POI FAQ:
ClassLoader classloader =
org.apache.poi.poifs.filesystem.POIFSFileSystem.class.getClassLoader();
URL res = classloader.getResource(
"org/apache/poi/poifs/filesystem/POIFSFileSystem.class");
String path = res.getPath();
System.out.println("Core POI came from " + path);
这将打印出您使用的POI的jar文件的文件名,这样你就可以在哪里工作的旧副本是来自并将其删除!
That will print out the filename of the POI jar you're using, so you can work out where the older copy is coming from and remove it!
这篇关于如何使用POI为DOC文件时,解决的NoSuchMethodError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!