javax.xml.stream.FactoryConfigurationError。在Android的docx4j库中没有找到提供者com.bea.xml.stream.MXParserFactory。

0 人关注

javax.xml.stream.FactoryConfigurationError。在Android的docx4j库中没有找到提供者com.bea.xml.stream.MXParserFactory。

我在安卓系统中导入docx4j库时遇到了这个错误 用于操作.docx文件或word文件中的复选框值。 这个错误是在读取word文件时出现的。 谢谢你的帮助。

Build.gradle文件。

    dependencies {
     implementation 'androidx.core:core-ktx:1.7.0'
    implementation 'androidx.appcompat:appcompat:1.5.1'
    implementation 'com.google.android.material:material:1.7.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
     implementation files('libs\\awt-bastardised-17v8.jar')
   //    implementation files('libs\\poishadow-all.jar')
  //    implementation files('libs\\jaxb-core-4.0.1.jar')
    //    implementation files('libs\\jaxb-api-2.3.0.jar')
     //    implementation files('libs\\jaxb-impl-4.0.1.jar')
   //    implementation files('libs\\javassist-3.29.2-GA.jar')
      //    implementation files('libs\\jaxb-runtime-4.0.1.jar')
  //    implementation group: 'javax.xml.bind', name: 'jaxb-api', version: '2.3.1'
     implementation group: 'javax.xml.bind', name: 'jaxb-api', version: '2.3.0'
   implementation group: 'com.sun.xml.bind', name: 'jaxb-core', version: '2.3.0'
      implementation group: 'com.sun.xml.bind', name: 'jaxb-impl', version: '2.3.0'
      implementation group: 'javax.activation', name: 'activation', version: '1.1.1'
       // https://mvnrepository.com/artifact/org.docx4j/docx4j
        implementation group: 'org.docx4j', name: 'docx4j', version: '6.1.2'
      implementation group: 'com.google.guava', name: 'guava', version: '27.0.1-android'
     //    implementation group: 'javax.xml.stream', name: 'stax-api', version: '1.0'
     // https://mvnrepository.com/artifact/stax/stax-api
     implementation group: 'stax', name: 'stax-api', version: '1.0.1'
     implementation group: 'org.docx4j', name: 'docx4j-MOXy-JAXBContext', version: '3.3.6'
      implementation group: 'org.slf4j', name: 'slf4j-api', version: '1.7.30'
    //    implementation files('libs/docx4j-core-8.3.7.jar')
   //    implementation files('libs/docx4j-JAXB-Internal-8.3.7.jar')
 //    implementation files('libs/docx4j-openxml-objects-8.3.7.jar')
 //    implementation files('libs/docx4j-openxml-objects-pml-8.3.7.jar')
  //    implementation files('libs/docx4j-openxml-objects-sml-8.3.7.jar')
    //    implementation files('libs/slf4j-api-1.7.2.jar')
   //    implementation files('libs/javax.xml.bind.jar')
  // https://mvnrepository.com/artifact/org.glassfish.jaxb/jaxb-runtime
  //    implementation("org.glassfish.jaxb:jaxb-runtime:4.0.0")
  //    implementation 'javax.xml.bind:jaxb-api:2.2.12'
 //    implementation files('libs/docx4j-core-11.4.8.jar')
   //    implementation files('libs/docx4j-openxml-objects-pml-11.4.8.jar')
    //    implementation files('libs/docx4j-openxml-objects-11.4.8.jar')
   //    implementation files('libs/docx4j-openxml-objects-sml-11.4.8.jar')
  //    implementation files('libs/jakarta.xml.bind-api-4.0.0.jar')
  //    // https://mvnrepository.com/artifact/com.sun.xml.bind/jaxb-core
  //    implementation("com.sun.xml.bind:jaxb-core:4.0.1")
     // https://mvnrepository.com/artifact/org.apache.commons/commons-compress
      //    implementation("org.apache.commons:commons-compress:1.22")
   // https://mvnrepository.com/artifact/jakarta.xml.bind/jakarta.xml.bind-api
   //    implementation("jakarta.xml.bind:jakarta.xml.bind-api:4.0.0")
  // https://mvnrepository.com/artifact/com.sun.xml.bind/jaxb-impl
  //    implementation("com.sun.xml.bind:jaxb-impl:4.0.0")

Kotlin Side:

 var resultLauncher =
    registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result ->
        if (result.resultCode == Activity.RESULT_OK) {
            // There are no request codes
            val data: Intent? = result.data
            try {
                data?.data?.let {
                    this.contentResolver?.openOutputStream(it)?.let {
                        this.contentResolver.openInputStream(data.data!!)?.let { it2 ->
                            val wordPackage: WordprocessingMLPackage =  Docx4J.load(it2)
                            val mainDocumentPart = wordPackage.mainDocumentPart
                            val list = mainDocumentPart.getJAXBNodesViaXPath("//w14:checkbox", false)
                            for (c in list) {
                                val element: JAXBElement<CTSdtCheckbox> = c as JAXBElement<CTSdtCheckbox>
                                val checkbox: CTSdtCheckbox = element.value
                                val list2 = mainDocumentPart.getJAXBNodesViaXPath("../..//w:t", element, false)
                                val chkSymbol: Text = (list2[0] as JAXBElement<Text>).value
                                val checkedVal: org.docx4j.w14.CTOnOff? = checkbox.checked
                                if (checkedVal?.getVal()?.compareTo("0") == 0) {
                                    checkedVal.setVal("1")
                                    chkSymbol.value = String(Character.toChars(0x2612))
                                } else {
                                    checkedVal?.setVal("0")
                                    chkSymbol.value = String(Character.toChars(0x2610))
            } catch (e: Exception) {