简体   繁体   English

无法从类型XHTMLImporter静态引用非静态方法setHyperlinkStyle(String)

[英]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.

相关问题 无法从类型teaminfo对非静态方法acceptadd(String)进行静态引用 - Cannot make a static reference to the non-static method acceptadd(String) from the type teaminfo 获取错误“无法对类型为Intent的非静态方法putExtra(String,String)进行静态引用” - Getting error “Cannot make a static reference to the non-static method putExtra(String, String) from the type Intent” 无法从DialogFragment类型静态引用非静态方法show(FragmentManager,String) - Cannot make a static reference to the non-static method show(FragmentManager, String) from the type DialogFragment 无法解析webView且无法从Activity类型静态引用非静态方法findViewById(int) - webView cannot be resolved & cannot make a static reference to the non-static method findViewById(int) from the type Activity 错误:“无法从类型Activity中对非静态方法startActivity(Intent)进行静态引用” - Error: “Cannot make a static reference to the non-static method startActivity(Intent) from the type Activity” 无法从类型Cmd对非静态方法getVideoURL()进行静态引用 - Cannot make a static reference to the non-static method getVideoURL() from the type Cmd 无法从View MainActivity.java类型静态引用非静态方法invalidate() - Cannot make a static reference to the non-static method invalidate() from the type View MainActivity.java Java - 无法从类型“something”中对非静态方法“something”进行静态引用 - Java - Cannot make a static reference to the non-static method "something" from the type "something" 无法使 static 引用非静态方法 --- 从类型 --- Java Bukkit Minecraft - Cannot make a static reference to the non-static method --- from the type --- Java Bukkit Minecraft 类型无法从类型View静态引用非静态方法setVisibility(int) - Type Cannot make a static reference to the non-static method setVisibility(int) from the type View
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM