phax / ph-commons

Java 11 Library with tons of utility classes required in all projects
Apache License 2.0
30 stars 18 forks source link

No static method newDefaultInstance()Ljavax/xml/parsers/SAXParserFactory #41

Closed Fangio92 closed 1 month ago

Fangio92 commented 11 months ago

Hello,

I am trying to use this library (ubl 2.1)in the Android Kotlin project but I am getting NoSuchMethodError when trying to parse invoice XML with UBL21Marshaller.invoice().read(invoice)

Complete stacktrace:

java.lang.NoSuchMethodError: No static method newDefaultInstance()Ljavax/xml/parsers/SAXParserFactory; in class Ljavax/xml/parsers/SAXParserFactory; or its super classes (declaration of 'javax.xml.parsers.SAXParserFactory' appears in /apex/com.android.art/javalib/core-libart.jar) at com.helger.xml.XMLFactory.createDefaultSAXParserFactory(XMLFactory.java:446) at com.helger.xml.serialize.read.SAXReaderFactory.createXMLReader(SAXReaderFactory.java:44) at com.helger.jaxb.IJAXBReader.read(IJAXBReader.java:99) at com.helger.jaxb.IJAXBReader.read(IJAXBReader.java:79) at com.helger.jaxb.IJAXBReader.read(IJAXBReader.java:143) at com.helger.jaxb.IJAXBReader.read(IJAXBReader.java:282) at com.dizdarevic.efakture.ui.invoiceList.InvoiceListViewModel$1.invokeSuspend(InvoiceListViewModel.kt:37) at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33) at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106) at kotlinx.coroutines.internal.LimitedDispatcher$Worker.run(LimitedDispatcher.kt:115) at kotlinx.coroutines.scheduling.TaskImpl.run(Tasks.kt:100) at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:584) at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:793) at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:697) at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:684) Suppressed: kotlinx.coroutines.internal.DiagnosticCoroutineContextException: [StandaloneCoroutine{Cancelling}@84ad87f, Dispatchers.IO]

If you could help me I would be grateful. Thanks.

phax commented 11 months ago

I am no Android developer, so I can't help you. However, I found https://developer.android.com/reference/javax/xml/parsers/SAXParserFactory while googling so I am pretty sure there is a way :)

Fangio92 commented 11 months ago

Thanks for the response. I spent some time figuring this out and obviously googling this before I reached out to you.

Exactly, there is SAXParserFactory but not a method called newDefaultInstance as you can see in the link you sent me - which is basically what this error NoSuchMethodError means. https://github.com/phax/ph-commons/blob/f8305c8b5f1b4fe02f2a6fb7ef3f71d4a0fa797e/ph-xml/src/main/java/com/helger/xml/XMLFactory.java#L446

phax commented 11 months ago

Ah, I see. That is a Java 9 method:

    /**
     * Creates a new instance of the {@code SAXParserFactory} builtin
     * system-default implementation.
     *
     * @return A new instance of the {@code SAXParserFactory} builtin
     *         system-default implementation.
     *
     * @since 9
     */
    public static SAXParserFactory newDefaultInstance() {
        return new SAXParserFactoryImpl();
    }
phax commented 1 month ago

Finally resolved this for the 11.1.7 release of ph-commons - this should to the trick