Example WorldWind application encounters AbstractMethodError when started
Asked Answered
R

2

8

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:

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.createDocumentBuilder is as follows:

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.

Is my problem actually with jogl, or something else?

Ridicule answered 4/9, 2013 at 14:6 Comment(0)
W
14

This is a classpath issue of some sort. AbstractMethodError is 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.

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.

Whoa answered 4/9, 2013 at 14:43 Comment(4)
I just checked the class type that's returned from DocumentBuilderFactory.newInstance(), and it's a DocumentBuilderFactoryImpl. The setFeature method is apparently implemented, and according to this, there shouldn't be anything that throws an AbstractMethodError in there.Ridicule
@Ridicule You should check what version of xerces is being loaded. You can do this by calling MyClass.class.getClassLoader().getResource("org/apache/xerces/jaxp/DocumentBuilderFactoryImpl.class"); and printing the resulting URL. Substitute a relevant class for MyClass.class. HelloWorldWind.class would probably do. Hopefully you can examine the jar file indicated by the URL to determine how old it is.Whoa
The jar that's being used is the one that came with WorldWind, version 2.5.0, so presumably it should work. I don't see any indication in the WorldWind forums that this is the problem.Ridicule
Yeah, you're on the right path. While the latest version of xerces implements that method, some previous versions didn't, including the one I'm using. Don't know why WorldWind isn't using the latest version in their downloads.Ridicule
M
2

You need go to class WWXML and replace:

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

with:

docBuilderFactory.setNamespaceAware(true);

the complete method on java is:

    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);
    }
}
Marin answered 14/7, 2016 at 16:53 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.