Eclipse Can't Find Latest Java 1.6 Methods for XMLOutputFactory
Asked Answered
C

3

7

I'm trying to use the newFactory() method for XMLOutputFactory, which was added in Java 6. But Eclipse keeps flagging newFactory() as undefined for the type XMLOutputFactory. JRE7 is the only runtime installed and in the build path of new Java projects. The project itself only has JRE7 (JRE System Library) and Ivy set up. The error I keep getting is

The method newFactory() is undefined for the type XMLOutputFactory

Any ideas how to get Eclipse to accept newFactory? Pretty much just using return XMLOutputFactory.newFactory() as the only place where the function is called.

Crescendo answered 5/8, 2013 at 22:21 Comment(6)
Have you set the compiler compliance level to 1.6 ?Titustityus
Yep. The default compliance level is set to 1.6 for new Java projects using Window->Preferences. For this project where the problem occurs specifically, compliance is set to 1.7 (otherwise get a bunch of other errors).Crescendo
So you can check in your import, that you really import the proper class.Titustityus
You mean the import statement? It's "import javax.xml.stream.XMLOutputFactory;" which seems right...Crescendo
Try to clean and rebuild. Sometimes this helps.Titustityus
Did that too. Also refreshed the project, all other projects, and resolved Ivy several times as well. Technically, I could just change newFactory() to newInstance() (old Java 5 equivalent which is still not deprecated) but I want to figure out why I can't use newFactory() as of now still.Crescendo
P
3

I had the same problem and it is resolved by using: XMLInputFactory factory = XMLInputFactory.newInstance(); you can visit:

click here for full description

Platon answered 31/1, 2017 at 14:34 Comment(0)
T
2

I had the same problem, and I fixed it by removing StAX from my classpath, because the version of XMLOutputFactory that comes with Java 7 provides the newFactory method, but the version of XMLOutputFactory that comes with StAX doesn't have it.

Trussing answered 15/5, 2014 at 3:32 Comment(1)
It worked. I excluded it from my gradle build using the dependenceis task to find the path and adding the exclude section to the parent dependencyHaunted
B
2

I build and imported Apache Phoenix project. class XMLResultHandler was giving the same error "The method newFactory() is undefined for the type XMLOutputFactory". I solved the problem by changing the order of Java System Library and stax-api-1.0-2.jar.

After correction eclipse project Library order snapshot

Begotten answered 1/11, 2017 at 19:52 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.