• 编译WorldWindJavav2.1.0中的ApplicationTemplate.java文件时有时报出“Exception in thread "main" java.lang.AbstractMethodError: javax.xml.parsers.DocumentBuilderFactory.setFeature(Ljava/lang/String;Z)V”错误的解决办法


    1 问题

    编译WorldWindJavav2.1.0中的ApplicationTemplate.java文件时有时报出如下错误:

    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.worldwind.awt.WorldWindowGLCanvas.<init>(WorldWindowGLCanvas.java:64)
    at gov.nasa.worldwindx.examples.ApplicationTemplate$AppPanel.createWorldWindow(ApplicationTemplate.java:88)
    at gov.nasa.worldwindx.examples.ApplicationTemplate$AppPanel.<init>(ApplicationTemplate.java:51)
    at gov.nasa.worldwindx.examples.ApplicationTemplate$AppFrame.createAppPanel(ApplicationTemplate.java:399)
    at gov.nasa.worldwindx.examples.ApplicationTemplate$AppFrame.initialize(ApplicationTemplate.java:336)
    at gov.nasa.worldwindx.examples.ApplicationTemplate$AppFrame.<init>(ApplicationTemplate.java:319)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
    at java.lang.reflect.Constructor.newInstance(Unknown Source)
    at java.lang.Class.newInstance(Unknown Source)
    at gov.nasa.worldwindx.examples.ApplicationTemplate.start(ApplicationTemplate.java:538)
    at gov.nasa.worldwindx.examples.ApplicationTemplate.main(ApplicationTemplate.java:563)

    2 原因

    不同jar包的多xml解析器冲突!!!

    3 解决

    解决方法:在使用DocumentBuilderFactory前加入这一行代码:

    System.setProperty("javax.xml.parsers.DocumentBuilderFactory", "com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl");

    完整代码如下:

    public static DocumentBuilder createDocumentBuilder(boolean isNamespaceAware)
        {
            System.setProperty("javax.xml.parsers.DocumentBuilderFactory", "com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl");//这一行是新增加的代码
            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);
                }
                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);
                }
            }
    
            try
            {
                return docBuilderFactory.newDocumentBuilder();
            }
            catch (ParserConfigurationException e)
            {
                String message = Logging.getMessage("XML.ParserConfigurationException");
                Logging.logger().finest(message);
                throw new WWRuntimeException(e);
            }
        }

    参考链接:解决javax.xml.parsers.DocumentBuilderFactory.setFeature(Ljava/lang/String;Z)V异常

  • 相关阅读:
    Mac 配置前端基本环境
    sass安装 使用
    SVG
    css规范
    [转载] Solaris命令使用
    solaris 10 基本使用
    dos taskkill 命令
    servicemix-3.2.1 内置的服务引擎和绑定组件
    servicemix-3.2.1 部署异常
    解析XML内容到User对象
  • 原文地址:https://www.cnblogs.com/rainbow70626/p/12381246.html
Copyright © 2020-2023  润新知