Java 示例 WorldWind 应用程序在启动时遇到 AbstractMethodError

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18616079/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-12 09:33:12  来源:igfitidea点击:

Example WorldWind application encounters AbstractMethodError when started

javaworldwind

提问by MBraedley

I've been tasked with creating an application using the WorldWind API, and to familiarize myself with the API, I tried running the "HelloWorldWind" example app. When I do, I get the following error stack:

我的任务是使用 WorldWind API 创建应用程序,为了熟悉 API,我尝试运行“HelloWorldWind”示例应用程序。当我这样做时,我收到以下错误堆栈:

Exception in thread "main" java.lang.AbstractMethodError: javax.xml.parsers.DocumentBuilderFactory.setFeature(Ljava/lang/String;Z)V
    at gov.nasa.worldwind.util.WWXML.createDocumentBuilder(WWXML.java:61)
    at gov.nasa.worldwind.util.WWXML.openDocumentStream(WWXML.java:236)
    at gov.nasa.worldwind.util.WWXML.openDocumentStream(WWXML.java:223)
    at gov.nasa.worldwind.util.WWXML.openDocumentFile(WWXML.java:175)
    at gov.nasa.worldwind.util.WWXML.openDocument(WWXML.java:148)
    at gov.nasa.worldwind.Configuration.loadConfigDoc(Configuration.java:131)
    at gov.nasa.worldwind.Configuration.<init>(Configuration.java:108)
    at gov.nasa.worldwind.Configuration.<clinit>(Configuration.java:76)
    at gov.nasa.worldwindx.examples.HelloWorldWind.main(HelloWorldWind.java:

WWXML.createDocumentBuilderis as follows:

WWXML.createDocumentBuilder如下:

public static DocumentBuilder createDocumentBuilder(boolean isNamespaceAware)
{
    DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
    docBuilderFactory.setNamespaceAware(isNamespaceAware);
    if (Configuration.getJavaVersion() >= 1.6)
    {
        try
        {
            docBuilderFactory.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd",
                false);    // Not getting past here
        }
        catch (ParserConfigurationException e)
        {   // Note it and continue on. Some Java5 parsers don't support the feature.
            String message = Logging.getMessage("XML.NonvalidatingNotSupported");
            Logging.logger().finest(message);
        }
    }
    ...

Reading some stuff online, people are blaming jogl, since I'm running on a 64-bit system, however, I already have the necessary jars in my build path. Additionally, trying the URL shown above in a browser returns a 404 page, which makes me think that might be the causeThe URL is just a way to format some preferences. Since I don't have the source for DocumentBuilderFactory.setFeature, I can't see what's messing up in there.

在线阅读一些东西,人们在责备jogl,因为我在 64 位系统上运行,但是,我的构建路径中已经有了必要的 jars。 此外,在浏览器中尝试上面显示的 URL 会返回一个 404 页面,这让我认为这可能是原因URL 只是格式化某些首选项的一种方式。由于我没有 的来源DocumentBuilderFactory.setFeature,我看不出那里有什么问题。

Is my problem actually with jogl, or something else?

我的问题实际上是jogl,还是别的什么?

采纳答案by Dev

This is a classpath issue of some sort. AbstractMethodErroris thrown when the JVM tries to invoke an abstract method (which is not allowed). DocumentBuilderFactory.setFeature(String, boolean)is an abstract method that was added to DocumentBuilderFactory in JavaSE 5, so implementations compiled against the J2SE 1.4.2 version would not have that method and this error would occur when setFeature(String, boolean)was called on them.

这是某种类路径问题。AbstractMethodError当 JVM 尝试调用抽象方法(这是不允许的)时抛出。DocumentBuilderFactory.setFeature(String, boolean)是在 JavaSE 5 中添加到 DocumentBuilderFactory 的抽象方法,因此针对 J2SE 1.4.2 版本编译的实现将没有该方法,并且在setFeature(String, boolean)调用它们时会发生此错误。

It is possible you have a old XML library on your classpath that returned an instance for DocumetnBuilderFactory.newInstance(). The problem may not be with JOGL, per se, it may just be that JOGL brought in an old XML library as a dependency.

您的类路径上可能有一个旧的 XML 库,它返回了DocumetnBuilderFactory.newInstance(). 问题本身可能不在于 JOGL,而可能只是 JOGL 引入了旧的 XML 库作为依赖项。

回答by Fran Raga

You need go to class WWXML and replace:

您需要转到 WWXML 类并替换:

docBuilderFactory.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd",
                false);

with:

和:

docBuilderFactory.setNamespaceAware(true);

the complete method on java is:

java上的完整方法是:

    public static DocumentBuilder createDocumentBuilder(boolean isNamespaceAware)
{
    DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();

    docBuilderFactory.setNamespaceAware(isNamespaceAware);

    if (Configuration.getJavaVersion() >= 1.6)
    {
        docBuilderFactory.setNamespaceAware(true);
    }

    try
    {
        return docBuilderFactory.newDocumentBuilder();
    }
    catch (ParserConfigurationException e)
    {
        String message = Logging.getMessage("XML.ParserConfigurationException");
        Logging.logger().finest(message);
        throw new WWRuntimeException(e);
    }
}