0

I have a problem while transforming the xslt to pdf in java, i am following the same process posted in this link

"Java Transformation to PDF".

Error:

`

Caused by: java.lang.NoSuchMethodError: org.apache.xmlgraphics.java2d.GraphicContext.<init>(Lorg/apache/xmlgraphics/java2d/GraphicContext;)V
    at org.apache.fop.render.intermediate.IFGraphicContext.<init>(IFGraphicContext.java:50)
    at org.apache.fop.render.intermediate.IFGraphicContext.clone(IFGraphicContext.java:56)
    at org.apache.fop.render.intermediate.IFRenderer.saveGraphicsState(IFRenderer.java:632)
    at org.apache.fop.render.intermediate.IFRenderer.startViewport(IFRenderer.java:885)
    at org.apache.fop.render.intermediate.IFRenderer.startVParea(IFRenderer.java:878)
    at org.apache.fop.render.AbstractRenderer.renderRegionViewport(AbstractRenderer.java:289)
    at org.apache.fop.render.intermediate.IFRenderer.renderRegionViewport(IFRenderer.java:731)
    at org.apache.fop.render.AbstractRenderer.renderPageAreas(AbstractRenderer.java:249)
    at org.apache.fop.render.AbstractRenderer.renderPage(AbstractRenderer.java:230)
    at org.apache.fop.render.intermediate.IFRenderer.renderPage(IFRenderer.java:580)
    at org.apache.fop.area.RenderPagesModel.addPage(RenderPagesModel.java:114)
    at org.apache.fop.layoutmgr.AbstractPageSequenceLayoutManager.finishPage(AbstractPageSequenceLayoutManager.java:312)
    at org.apache.fop.layoutmgr.PageSequenceLayoutManager.finishPage(PageSequenceLayoutManager.java:167)
    at org.apache.fop.layoutmgr.PageSequenceLayoutManager.activateLayout(PageSequenceLayoutManager.java:109)
    at org.apache.fop.area.AreaTreeHandler.endPageSequence(AreaTreeHandler.java:238)
    at org.apache.fop.fo.pagination.PageSequence.endOfNode(PageSequence.java:120)
    at org.apache.fop.fo.FOTreeBuilder$MainFOHandler.endElement(FOTreeBuilder.java:349)
    at org.apache.fop.fo.FOTreeBuilder.endElement(FOTreeBuilder.java:177)
    at net.sf.saxon.event.ContentHandlerProxy.endElement(ContentHandlerProxy.java:391)
    at net.sf.saxon.event.ProxyReceiver.endElement(ProxyReceiver.java:174)
    at net.sf.saxon.event.NamespaceReducer.endElement(NamespaceReducer.java:213)
    at net.sf.saxon.event.ComplexContentOutputter.endElement(ComplexContentOutputter.java:417)
    at net.sf.saxon.instruct.ElementCreator.processLeavingTail(ElementCreator.java:301)
    at net.sf.saxon.instruct.Block.processLeavingTail(Block.java:409)
    at net.sf.saxon.instruct.Instruction.process(Instruction.java:94)
    at net.sf.saxon.instruct.ElementCreator.processLeavingTail(ElementCreator.java:298)
    at net.sf.saxon.instruct.Template.applyLeavingTail(Template.java:175)
    at net.sf.saxon.instruct.ApplyTemplates.applyTemplates(ApplyTemplates.java:343)
    at net.sf.saxon.Controller.transformDocument(Controller.java:1736)
    at net.sf.saxon.Controller.transform(Controller.java:1560)
    at mypackage.v2.business.pdf.XMLtoPDF.convertXMLPDF(XMLtoPDF.java:103)
    ... 51 more
java.lang.ClassCastException: java.lang.NoSuchMethodError cannot be cast to java.lang.Exception

` Please let me know what could be the problem.

Community
  • 1
  • 1
Java Learner
  • 311
  • 2
  • 10
  • 26

1 Answers1

0

As described in the documentation

Thrown if an application tries to call a specified method of a class (either static or instance), and that class no longer has a definition of that method.

Here's how this can happen. Imagine you built some code that used a library with a method called foo(). You compiled your project and then later decided to upgrade the library. You do this by overwriting the old jar file with the new one. You don't recompile your code.

But what you didn't know is the new library removed the foo() method. Now if you run your code, it will throw this exception because your compile code calls this method and it's no longer there.

In your specific case, this isn't necessarily your code with the problem. It could be that you have one library that uses another library and the problem is there (for example, Library X uses version 2 of Library Y, but you only have Library Y version 1 in your classpath). If this is happening, you need to make sure the libraries are using the version they expect.

For your specific problem, you need to find the version of the jar that has org.apache.xmlgraphics.java2d.GraphicContext in it and it needs to have a constructor that takes a... list of org/apache/xmlgraphics/java2d/GraphicContext... maybe. I forget what (L...;)V means.

Daniel Kaplan
  • 62,768
  • 50
  • 234
  • 356