【问题标题】:Android Studio DatatypeFactoryImpl not found未找到 Android Studio DatatypeFactoryImpl
【发布时间】:2018-12-23 05:06:50
【问题描述】:

我尝试使用 android studio 生成 XML 文件,但出现此错误:

 Caused by: javax.xml.datatype.DatatypeConfigurationException: Provider org.apache.xerces.jaxp.datatype.DatatypeFactoryImpl not found.

问题来自“JAXBContext”行。 我有一个使 XML 文件的代码为的函数

        try {

        File file = new File("D:\\Github\\Comedu\\file.xml");
        JAXBContext jaxbContext = JAXBContext.newInstance(Resultat.class);
        Marshaller jaxbMarshaller = jaxbContext.createMarshaller();

        // output pretty printed
        jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);

        jaxbMarshaller.marshal(this, file);
        jaxbMarshaller.marshal(this, System.out);

    } catch (JAXBException e) {
        e.printStackTrace();
    }

在 android studio 上,我将 xerces 包添加到我的构建路径中,所以我不知道如何解决这个问题。

【问题讨论】:

    标签: java android xml xerces


    【解决方案1】:

    如果你是 Android 开发者,如文档中所说的Note that you must supply your own implementation (such as Xerces); Android does not ship with a default implementation. https://developer.android.com/reference/javax/xml/datatype/DatatypeFactory.html#newInstance%28%29

    所以,尝试添加依赖xercesImpl

    马文:

    <!-- https://mvnrepository.com/artifact/xerces/xercesImpl -->
    <dependency>
        <groupId>xerces</groupId>
        <artifactId>xercesImpl</artifactId>
        <version>2.12.0</version>
    </dependency>
    

    分级:

    // https://mvnrepository.com/artifact/xerces/xercesImpl
    compile group: 'xerces', name: 'xercesImpl', version: '2.12.0'
    

    【讨论】:

      猜你喜欢
      • 2014-03-05
      • 2019-04-06
      • 1970-01-01
      • 1970-01-01
      • 2021-10-04
      • 2020-07-12
      • 1970-01-01
      • 1970-01-01
      • 2017-01-25
      相关资源
      最近更新 更多