大家。
当我尝试将图表导出为pdf文件时,我收到此错误。 我从Itext站点获取了示例,并在我的代码中实现了它。 这是导出
的代码片段else if (isGrafico(componente)) {
System.out.println("============= Encontrou um Grafico");
Configuration conf = ((GraficoComp) componente)
.getGraficoGerado().getConfiguration();
String svgStr = SVGGenerator.getInstance().generate(conf);
System.out.println(svgStr);
/** The SVG document factory. */
SAXSVGDocumentFactory factory;
/** The SVG bridge context. */
BridgeContext ctx;
/** The GVT builder */
GVTBuilder builder;
String parser = XMLResourceDescriptor.getXMLParserClassName();
factory = new SAXSVGDocumentFactory(parser);
UserAgent userAgent = new UserAgentAdapter();
DocumentLoader loader = new DocumentLoader(userAgent);
// Ok =========================================================
// \/ Error happens in this line
ctx = new BridgeContext(userAgent, loader);
ctx.setDynamicState(BridgeContext.DYNAMIC);
builder = new GVTBuilder();
// =============================================
PdfContentByte cb = writer.getDirectContent();
PdfTemplate chart = cb.createTemplate(900, 900);
drawSvg(factory,builder,ctx,chart, svgStr);
cb.addTemplate(chart, 0, 0);
以下是错误:
2014-06-17T13:46:08.623+0000|WARNING: ApplicationDispatcher[/AmbienteRelatorio] PWC1231: Servlet.service() for servlet Ambienterelatorio Application threw exception
java.lang.NoSuchMethodError: org.json.JSONObject.put(Ljava/lang/String;Ljava/util/Collection;)Lorg/json/JSONObject;
at com.vaadin.server.VaadinService.createCriticalNotificationJSON(VaadinService.java:1574)
at com.vaadin.server.VaadinService.handleExceptionDuringRequest(VaadinService.java:1424)
at com.vaadin.server.VaadinService.handleRequest(VaadinService.java:1402)
at com.vaadin.server.VaadinPortlet.handleRequest(VaadinPortlet.java:435)
at com.vaadin.server.VaadinPortlet.serveResource(VaadinPortlet.java:538)
at com.liferay.portlet.FilterChainImpl.doFilter(FilterChainImpl.java:118)
at com.liferay.portal.kernel.portlet.PortletFilterUtil.doFilter(PortletFilterUtil.java:71)
at com.liferay.portal.kernel.servlet.PortletServlet.service(PortletServlet.java:93)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1539)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:343)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:217)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:72)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilter.doFilter(InvokerFilter.java:70)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:217)
at org.apache.catalina.core.ApplicationDispatcher.doInvoke(ApplicationDispatcher.java:785)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:649)
at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:483)
at org.apache.catalina.core.ApplicationDispatcher.doDispatch(ApplicationDispatcher.java:454)
at org.apache.catalina.core.ApplicationDispatcher.dispatch(ApplicationDispatcher.java:350)
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:300)
at com.liferay.portlet.InvokerPortletImpl.invoke(InvokerPortletImpl.java:634)
at com.liferay.portlet.InvokerPortletImpl.invokeResource(InvokerPortletImpl.java:746)
at com.liferay.portlet.InvokerPortletImpl.serveResource(InvokerPortletImpl.java:503)
at com.liferay.portal.action.LayoutAction.processPortletRequest(LayoutAction.java:941)
at com.liferay.portal.action.LayoutAction.processLayout(LayoutAction.java:664)
at com.liferay.portal.action.LayoutAction.execute(LayoutAction.java:244)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:431)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:236)
at com.liferay.portal.struts.PortalRequestProcessor.process(PortalRequestProcessor.java:174)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:754)
at com.liferay.portal.servlet.MainServlet.callParentService(MainServlet.java:533)
at com.liferay.portal.servlet.MainServlet.service(MainServlet.java:510)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
答案 0 :(得分:1)
这不是一个iText问题。您的堆栈跟踪无法在任何地方引用iText。它指的是Liferay,Struts和Vaadin,它告诉你关于http://www.json.org/的问题
你指的是我写的一个例子,但AFAIK我并没有在任何地方使用JSON。拥有NoSuchMethodError
可能是由很多事情造成的:
关于案例3.例如使用方法栏()来获取类Foo。
public class Foo {
public void bar() {}
}
您正在申请中使用此课程。
Foo foo = new Foo();
foo.bar();
现在突然bar()
方法改变如下:
public class Foo {
public int bar() { return 0; }
}
如果替换包含Foo
类的jar,则应用程序将抛出NoSuchMethodError
,因为方法的签名已更改。这可能令人困惑,因为方法就在那里。只是您的应用无法找到它,因为您的应用正在寻找void bar()
而不是int bar()
。