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.

Paul Vargas
  • 41,222
  • 15
  • 102
  • 148
Shayon Saleh
  • 419
  • 3
  • 7
  • 15

3 Answers3

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.

davidwebster48
  • 604
  • 1
  • 8
  • 21
  • 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 dependency – Juan Calero Dec 23 '16 at 12:59
2

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

click here for full description

Marcos Delgado
  • 177
  • 3
  • 13
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

Arshad
  • 21
  • 2