我创建了一个用于绘制报告的 GUI:
图形用户界面:
package aatmPackage;
import java.awt.Color;
import java.awt.Shape;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.plot.XYPlot;
import org.jfree.chart.renderer.xy.XYItemRenderer;
import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer;
import org.jfree.chart.title.TextTitle;
import org.jfree.data.xy.XYSeries;
import org.jfree.data.xy.XYSeriesCollection;
import org.jfree.util.ShapeUtilities;
public class GuiAATM extends javax.swing.JFrame {
...
private void reportButtonActionPerformed(java.awt.event.ActionEvent evt) {
report Report = new report();
setReportLog("Report Generated Successfully\n");
}
}
我创建了另一个项目并对其进行了测试,它可以很好地生成报告。现在,当我将该类添加到我的 GuiAATM 项目时,(用户单击报告按钮时应该生成报告)我收到以下错误:
log4j:WARN Parsing warning 2 and column 38
log4j:WARN URI was not reported to parser for entity [dtd]
log4j:WARN Parsing warning 2 and column 38
log4j:WARN missing system ID, using log4j.dtd
log4j:ERROR Could not parse url [jar:file:/D:/Glaswegian/Java/DynamicCharts/dynamicreports-3.1.0-project-with-dependencies%20(1)/dynamicreports-3.1.0/dist/dynamicreports-examples-3.1.0-sources.jar!/log4j.xml].
gnu.xml.dom.DomEx: The operation violates XML Namespaces.
More Information: xmlns is reserved
Node Name: #document
at gnu.xml.dom.DomDocument.createAttributeNS(DomDocument.java:589)
at gnu.xml.dom.DomDocument.createAttribute(DomDocument.java:561)
at gnu.xml.dom.DomDocument.defaultAttributes(DomDocument.java:456)
at gnu.xml.dom.DomDocument.createElementNS(DomDocument.java:440)
at gnu.xml.pipeline.DomConsumer$Handler.startElement(DomConsumer.java:602)
at gnu.xml.dom.Consumer$Backdoor.startElement(Consumer.java:203)
at gnu.xml.pipeline.EventFilter.startElement(EventFilter.java:570)
at gnu.xml.pipeline.ValidationConsumer.startElement(ValidationConsumer.java:1177)
at gnu.xml.aelfred2.SAXDriver.startElement(SAXDriver.java:836)
at gnu.xml.aelfred2.XmlParser.parseElement(XmlParser.java:1037)
at gnu.xml.aelfred2.XmlParser.parseDocument(XmlParser.java:416)
at gnu.xml.aelfred2.XmlParser.doParse(XmlParser.java:167)
at gnu.xml.aelfred2.SAXDriver.parse(SAXDriver.java:320)
at gnu.xml.aelfred2.XmlReader.parse(XmlReader.java:294)
at gnu.xml.dom.JAXPFactory$JAXPBuilder.parse(JAXPFactory.java:186)
at javax.xml.parsers.DocumentBuilder.parse(DocumentBuilder.java:177)
at org.apache.log4j.xml.DOMConfigurator$2.parse(DOMConfigurator.java:612)
at org.apache.log4j.xml.DOMConfigurator.doConfigure(DOMConfigurator.java:711)
at org.apache.log4j.xml.DOMConfigurator.doConfigure(DOMConfigurator.java:618)
at org.apache.log4j.helpers.OptionConverter.selectAndConfigure(OptionConverter.java:470)
at org.apache.log4j.LogManager.<clinit>(LogManager.java:122)
at org.apache.log4j.Logger.getLogger(Logger.java:104)
at org.apache.commons.logging.impl.Log4JLogger.getLogger(Log4JLogger.java:289)
at org.apache.commons.logging.impl.Log4JLogger.<init>(Log4JLogger.java:109)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:525)
at org.apache.commons.logging.impl.LogFactoryImpl.createLogFromClass(LogFactoryImpl.java:1116)
at org.apache.commons.logging.impl.LogFactoryImpl.discoverLogImplementation(LogFactoryImpl.java:914)
at org.apache.commons.logging.impl.LogFactoryImpl.newInstance(LogFactoryImpl.java:604)
at org.apache.commons.logging.impl.LogFactoryImpl.getInstance(LogFactoryImpl.java:336)
at org.apache.commons.logging.impl.LogFactoryImpl.getInstance(LogFactoryImpl.java:310)
at org.apache.commons.logging.LogFactory.getLog(LogFactory.java:685)
at net.sf.dynamicreports.report.defaults.Defaults.<clinit>(Defaults.java:42)
at net.sf.dynamicreports.design.transformation.TemplateTransform.getPageHeight(TemplateTransform.java:663)
at net.sf.dynamicreports.design.transformation.PageTransform.transform(PageTransform.java:44)
at net.sf.dynamicreports.design.base.DRDesignReport.transform(DRDesignReport.java:132)
at net.sf.dynamicreports.design.base.DRDesignReport.<init>(DRDesignReport.java:107)
at net.sf.dynamicreports.design.base.DRDesignReport.<init>(DRDesignReport.java:99)
at net.sf.dynamicreports.jasper.builder.JasperReportBuilder.toJasperReportDesign(JasperReportBuilder.java:260)
at net.sf.dynamicreports.jasper.builder.JasperReportBuilder.getJasperParameters(JasperReportBuilder.java:287)
at net.sf.dynamicreports.jasper.builder.JasperReportBuilder.toJasperPrint(JasperReportBuilder.java:298)
at net.sf.dynamicreports.jasper.builder.JasperReportBuilder.show(JasperReportBuilder.java:327)
at aatmPackage.report.build(report.java:70)
at aatmPackage.report.<init>(report.java:26)
at aatmPackage.GuiAATM.reportButtonActionPerformed(GuiAATM.java:1214)
at aatmPackage.GuiAATM.access$400(GuiAATM.java:34)
at aatmPackage.GuiAATM$5.actionPerformed(GuiAATM.java:968)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2018)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2341)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:252)
at java.awt.Component.processMouseEvent(Component.java:6505)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3321)
at java.awt.Component.processEvent(Component.java:6270)
at java.awt.Container.processEvent(Container.java:2229)
at java.awt.Component.dispatchEventImpl(Component.java:4861)
at java.awt.Container.dispatchEventImpl(Container.java:2287)
at java.awt.Component.dispatchEvent(Component.java:4687)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4832)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4492)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4422)
at java.awt.Container.dispatchEventImpl(Container.java:2273)
at java.awt.Window.dispatchEventImpl(Window.java:2719)
at java.awt.Component.dispatchEvent(Component.java:4687)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:723)
at java.awt.EventQueue.access$200(EventQueue.java:103)
at java.awt.EventQueue$3.run(EventQueue.java:682)
at java.awt.EventQueue$3.run(EventQueue.java:680)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:87)
at java.awt.EventQueue$4.run(EventQueue.java:696)
at java.awt.EventQueue$4.run(EventQueue.java:694)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:693)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:244)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:163)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:151)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:147)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:139)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:97)
log4j:WARN No appenders could be found for logger (net.sf.jasperreports.extensions.ExtensionsEnvironment).
log4j:WARN Please initialize the log4j system properly.
Exception in thread "AWT-EventQueue-0" java.lang.AbstractMethodError: gnu.xml.dom.DomElement.getTextContent()Ljava/lang/String;
at net.sf.jasperreports.engine.fonts.SimpleFontExtensionHelper.parseExportFonts(SimpleFontExtensionHelper.java:317)
at net.sf.jasperreports.engine.fonts.SimpleFontExtensionHelper.parseFontFamily(SimpleFontExtensionHelper.java:285)
at net.sf.jasperreports.engine.fonts.SimpleFontExtensionHelper.parseFontFamilies(SimpleFontExtensionHelper.java:232)
at net.sf.jasperreports.engine.fonts.SimpleFontExtensionHelper.loadFontFamilies(SimpleFontExtensionHelper.java:193)
at net.sf.jasperreports.engine.fonts.SimpleFontExtensionHelper.loadFontFamilies(SimpleFontExtensionHelper.java:162)
at net.sf.jasperreports.engine.fonts.FontExtensionsRegistry.getExtensions(FontExtensionsRegistry.java:56)
at net.sf.jasperreports.extensions.DefaultExtensionsRegistry.getExtensions(DefaultExtensionsRegistry.java:110)
at net.sf.jasperreports.engine.util.JRStyledTextParser.<clinit>(JRStyledTextParser.java:83)
at net.sf.jasperreports.engine.fill.JRBaseFiller.<init>(JRBaseFiller.java:121)
at net.sf.jasperreports.engine.fill.JRVerticalFiller.<init>(JRVerticalFiller.java:88)
at net.sf.jasperreports.engine.fill.JRVerticalFiller.<init>(JRVerticalFiller.java:103)
at net.sf.jasperreports.engine.fill.JRVerticalFiller.<init>(JRVerticalFiller.java:61)
at net.sf.jasperreports.engine.fill.JRFiller.createFiller(JRFiller.java:153)
at net.sf.jasperreports.engine.fill.JRFiller.fill(JRFiller.java:82)
at net.sf.jasperreports.engine.JasperFillManager.fill(JasperFillManager.java:653)
at net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:969)
at net.sf.dynamicreports.jasper.builder.JasperReportBuilder.toJasperPrint(JasperReportBuilder.java:308)
at net.sf.dynamicreports.jasper.builder.JasperReportBuilder.show(JasperReportBuilder.java:327)
at aatmPackage.report.build(report.java:70)
at aatmPackage.report.<init>(report.java:26)
at aatmPackage.GuiAATM.reportButtonActionPerformed(GuiAATM.java:1214)
at aatmPackage.GuiAATM.access$400(GuiAATM.java:34)
at aatmPackage.GuiAATM$5.actionPerformed(GuiAATM.java:968)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2018)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2341)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:252)
at java.awt.Component.processMouseEvent(Component.java:6505)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3321)
at java.awt.Component.processEvent(Component.java:6270)
at java.awt.Container.processEvent(Container.java:2229)
at java.awt.Component.dispatchEventImpl(Component.java:4861)
at java.awt.Container.dispatchEventImpl(Container.java:2287)
at java.awt.Component.dispatchEvent(Component.java:4687)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4832)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4492)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4422)
at java.awt.Container.dispatchEventImpl(Container.java:2273)
at java.awt.Window.dispatchEventImpl(Window.java:2719)
at java.awt.Component.dispatchEvent(Component.java:4687)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:723)
at java.awt.EventQueue.access$200(EventQueue.java:103)
at java.awt.EventQueue$3.run(EventQueue.java:682)
at java.awt.EventQueue$3.run(EventQueue.java:680)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:87)
at java.awt.EventQueue$4.run(EventQueue.java:696)
at java.awt.EventQueue$4.run(EventQueue.java:694)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:693)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:244)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:163)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:151)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:147)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:139)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:97)
BUILD SUCCESSFUL (total time: 6 seconds)
我的 report.java 文件是:
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package aatmPackage;
import static net.sf.dynamicreports.report.builder.DynamicReports.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import java.awt.Color;
import net.sf.dynamicreports.examples.Templates;
import net.sf.dynamicreports.report.builder.style.StyleBuilder;
import net.sf.dynamicreports.report.constant.HorizontalAlignment;
import net.sf.dynamicreports.report.datasource.DRDataSource;
import net.sf.dynamicreports.report.exception.DRException;
import net.sf.jasperreports.engine.JRDataSource;
import net.sf.dynamicreports.report.builder.style.FontBuilder;
public class report {
public report() {
build();
}
private void build() {
StyleBuilder boldStyle = stl.style().bold();
// FontBuilder boldFont = stl.fontArialBold().setFontSize(12);
Color MAROON = new Color(122, 5, 5);
StyleBuilder titleLineOne = stl.style(boldStyle).setHorizontalAlignment
(HorizontalAlignment.RIGHT).setFontSize(15).setForegroundColor
(MAROON);
StyleBuilder titleNextLine = stl.style(boldStyle).setHorizontalAlignment
(HorizontalAlignment.RIGHT).setFontSize(12).setForegroundColor
(MAROON);
StyleBuilder bodyTitleStyle = stl.style(boldStyle).setHorizontalAlignment
(HorizontalAlignment.LEFT).setFontSize(12);
StyleBuilder bodyStyle = stl.style().setFontSize(11);
StyleBuilder signatureStyle = stl.style(boldStyle).setHorizontalAlignment
(HorizontalAlignment.RIGHT);
StyleBuilder footerLeft = stl.style(boldStyle).setHorizontalAlignment
(HorizontalAlignment.LEFT).setForegroundColor
(MAROON) ;
StyleBuilder footerRight = stl.style(boldStyle).setHorizontalAlignment
(HorizontalAlignment.RIGHT).setForegroundColor
(MAROON) ;
//BufferedImage img = new BufferedImage(1200,1200,BufferedImage.TYPE_INT_RGB);
BufferedImage img = null;
try {
// img = ImageIO.read(new File("D:/Hysteresis.png"));
img = ImageIO.read(new File("D:/Hysteresis.png"));
} catch (IOException e) {
}
BufferedImage logo = null;
try {
// img = ImageIO.read(new File("D:/Hysteresis.png"));
logo = ImageIO.read(new File("D:/Logo.jpg"));
} catch (IOException e) {
}
try {
report()//create new report design
// .setColumnTitleStyle(boldStyle)
// .setColumnStyle(boldStyle)
.highlightDetailEvenRows()
.columns(//add columns
col.column(null,"Col_1", type.stringType())
.setStyle(bodyStyle),
col.column(null,"Col_2", type.stringType())
.setStyle(bodyStyle)
)
.summary(
cmp.verticalList()
// .add(cmp.filler().setStyle(stl.style().setTopBorder(stl.pen2Point())).setFixedHeight(10))
.add(
cmp.text("\n"),
cmp.filler().setStyle(stl.style().setTopBorder(stl.pen1Point())),
cmp.text("\nHYSTERISIS PLOT\n").setStyle(bodyTitleStyle),
cmp.text(" 1.\n").setStyle(
bodyStyle),
// .add(cmp.image(getClass().getResourceAsStream
// ("D:/Hysteresis.png")).setFixedDimension(300, 300))
cmp.horizontalList()
.add(cmp.image(img).setFixedDimension(350, 250),
//cmp.text("ANALYSIS\n").setStyle(bodyTitleStyle),
cmp.text("Right Lobe Change:160.04%\n").setStyle(bodyStyle),
cmp.text("Left Lobe Change: 35.38%\n").setStyle(bodyStyle),
cmp.text("Hysteresis Change: 81.50%\n").setStyle(bodyStyle)),
//cmp.filler().setStyle(stl.style().setTopBorder(stl.pen1Point())),
cmp.text("REMARKS\n\n\n\n\n\n\n\n").setStyle(bodyTitleStyle),
cmp.text("Doctor Signature").setStyle(signatureStyle))
)
.title(
cmp.horizontalList()
.add(
cmp.image(logo).setFixedDimension(70, 70),
cmp.verticalList()
.add(
cmp.text(" Ltd").setStyle(titleLineOne),
cmp.text(", ").setStyle(titleNextLine),
cmp.text("Mobile +").setStyle(titleNextLine))
)
/* cmp.horizontalList()
.add( cmp.text("Allahabad Bypass Varanasi").setStyle(boldCenteredStyle))
*/
.newRow()
.add(cmp.filler().setStyle(stl.style().setTopBorder(stl.pen2Point())).setFixedHeight(10))
)//shows report title
// .pageFooter(cmp.pageXofY())//shows number of page at page footer
.pageFooter(
Templates.footerComponent,
//cmp.text(" \t\t\t\t\t\t\t\t"
// + " ")
cmp.horizontalList()
.add(cmp.text("Emsol Software Solution").setStyle(footerLeft),
cmp.text("copyright: gauravbvelex@gmail.com").setStyle(footerRight))
)
.setDataSource(createDataSource())//set datasource
.show();//create and show report
} catch (DRException e) {
e.printStackTrace();
}
}
private JRDataSource createDataSource() {
DRDataSource dataSource = new DRDataSource("Col_1", "Col_2");
dataSource.add("Name","Sample");
dataSource.add("Age","26");
dataSource.add("Sex","Female");
dataSource.add("Weight","53 Kg");
dataSource.add("BMI","20");
dataSource.add("Massage Duration (Mins)","4.5");
dataSource.add("RPM","26");
dataSource.add("Doctor Attended","Doctor");
dataSource.add("Date","24-Feb-2013");
return dataSource;
}
}
此报告在作为单独项目运行时运行良好,然后我尝试创建示例 jFrame,然后添加此 .java 文件并运行它。当我单击按钮时,它创建了报告。但是实际项目(我在 20 天内开发的 GUI 和功能)会引发显示的错误。我什至尝试将报告代码放入 gui 文件本身,但得到了同样的错误。我无法解决问题。
有人可以帮忙吗?
谢谢