[英]Cannot make a static reference to the non-static method setHyperlinkStyle(String) from the type XHTMLImporter
Currently I'm using doxc4j version 3.2.1
当前我正在使用
doxc4j version 3.2.1
The default argument for the method setHyperlinkStyle()
is "Hyperlink". setHyperlinkStyle()
方法的默认参数是“ Hyperlink”。
So basically it would look like this in my code: 所以基本上在我的代码中看起来像这样:
XHTMLImporter.setHyperlinkStyle("Hyperlink");
Can someone explain why I got error: Cannot make a static reference to the non-static method setHyperlinkStyle(String) from the type XHTMLImporter
有人可以解释我为什么会出错:
Cannot make a static reference to the non-static method setHyperlinkStyle(String) from the type XHTMLImporter
While it is working fine when using some previous version. 当使用某些早期版本时,它可以正常工作。
You will need to create an instance of XHTMLImporter
, instead of trying to use a method in a static context. 您将需要创建
XHTMLImporter
的实例,而不是尝试在静态上下文中使用方法。
XHTMLImporter xi = new XHTMLImporter();
xi.setHyperlinkStyle("Hyperlink");
and use xi
where you need it 并在需要的地方使用
xi
And the other thing you can do, since you say that XHTMLImporter is an interface is that you can instantiate an anonymous class that implements the interface, and then call the hyperlink style from there. 另外,您可以做的另一件事是,因为您说XHTMLImporter是一个接口,所以您可以实例化一个实现该接口的匿名类,然后从那里调用超链接样式。 I would read the documentation for the new version of your library though.
不过,我会阅读您库的新版本的文档。 it sounds like they changed their API, and just naïvely trying to make stuff work could lead you down rabbitholes of stuff not working.
听起来好像他们更改了他们的API,只是天真地尝试使工作正常,可能会导致您无法正常工作。
This is an example extracted of project samples folder in github. 这是从github中的项目示例文件夹中提取的示例。
XHTMLImporter xHTMLImporter= null;
Class<?> xhtmlImporterClass = null;
try {
xhtmlImporterClass = Class.forName("org.docx4j.convert.in.xhtml.XHTMLImporterImpl");
Constructor<?> ctor = xhtmlImporterClass.getConstructor(WordprocessingMLPackage.class);
xHTMLImporter = (XHTMLImporter) ctor.newInstance(pkg);
} catch (Exception e) {
log.error("docx4j-XHTMLImport jar not found. Please add this to your classpath.");
log.error(e.getMessage(), e);
return xhtmlError(sdtParent, docContainer, docfrag, "Missing XHTML Handler!");
}
This link found uses of XHTMLImporter, you can found more examples. 该链接找到了XHTMLImporter的用法,您可以找到更多示例。 https://github.com/plutext/docx4j/search?utf8=%E2%9C%93&q=xhtmlimporter
https://github.com/plutext/docx4j/search?utf8=%E2%9C%93&q=xhtmlimporter
If you can't use XHTMLImportImporterImpl try to add this dependency 如果您不能使用XHTMLImportImporterImpl尝试添加此依赖项
<dependency>
<groupId>org.docx4j</groupId>
<artifactId>docx4j-ImportXHTML</artifactId>
<version>3.2.1</version>
</dependency>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.