0

I tried to run this code but it give me error like this:

2013-03-26 22:45:55,546 [pool-2-thread-1] ERROR griffon.util.GriffonExceptionHandler - Uncaught Exception
org.codehaus.groovy.runtime.InvokerInvocationException: java.lang.NoClassDefFoundError: com/lowagie/text/SplitCharacter
    at org.codehaus.griffon.runtime.util.AbstractUIThreadHandler$1.run(AbstractUIThreadHandler.java:41)
Caused by: java.lang.NoClassDefFoundError: com/lowagie/text/SplitCharacter
    at net.sf.jasperreports.engine.JasperExportManager.exportToPdfFile(JasperExportManager.java:145)
    at net.sf.jasperreports.engine.JasperExportManager.exportReportToPdfFile(JasperExportManager.java:497)
    at net.sf.jasperreports.engine.JasperExportManager$exportReportToPdfFile.call(Unknown Source)
    at report.ReportController$_closure1_closure2.doCall(ReportController.groovy:28)
    at report.ReportController$_closure1_closure2.doCall(ReportController.groovy)
    ... 1 more
Caused by: java.lang.ClassNotFoundException: com.lowagie.text.SplitCharacter
    ... 6 more

Here's the code:

--ReportController.groovy--

import net.sf.jasperreports.engine.JasperCompileManager
import net.sf.jasperreports.engine.JasperExportManager
import net.sf.jasperreports.engine.JasperFillManager
import net.sf.jasperreports.engine.data.JRBeanCollectionDataSource
import net.sf.jasperreports.swing.JRViewer

class ReportController {
    // these will be injected by Griffon
    def model
    def view

    def report = {
        def jasperParameter = [:]
            jasperParameter.REPORT_TITLE = "Test report"

        def jasperReport = JasperCompileManager.compileReport("report.jrxml")

        def mapData = [:]
            mapData.name = "abc"
            mapData.price = 1234
            def datas = [mapData]
                JRBeanCollectionDataSource dataSource = new JRBeanCollectionDataSource(datas)

        def jasperPrint = JasperFillManager.fillReport(jasperReport, jasperParameter, dataSource)

        JasperExportManager.exportReportToPdfFile(jasperPrint, "g:/sample.pdf")

        JRViewer viewer = new JRViewer(jasperPrint)

        viewer.setOpaque(true)
        viewer.setVisible(true)

        def jf = new javax.swing.JFrame ()

        jf.add(viewer)
        jf.setSize(800, 600)
        jf.setVisible(true)
        jf.setDefaultCloseOperation(EXIT_ON_CLOSE)
    }
}

--ReportView.groovy--

package report

application(title: 'report',
  preferredSize: [320, 240],
  pack: true,
  //location: [50,50],
  locationByPlatform: true,
  iconImage:   imageIcon('/griffon-icon-48x48.png').image,
  iconImages: [imageIcon('/griffon-icon-48x48.png').image,
               imageIcon('/griffon-icon-32x32.png').image,
               imageIcon('/griffon-icon-16x16.png').image]) {
    gridLayout (cols: 1, rows: 1)
    button (text: 'report', actionPerformed: controller.& report)
}

--report.jrxml-- (I put this file in /staging folder)

<?xml version="1.0" encoding="UTF-8"?>
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="test" pageWidth="800" pageHeight="1200" columnWidth="555" leftMargin="25" rightMargin="25" topMargin="30" bottomMargin="30">
    <property name="ireport.zoom" value="1.0"/>
    <property name="ireport.x" value="0"/>
    <property name="ireport.y" value="0"/>
    <queryString>
        <![CDATA[]]>
    </queryString>
    <pageHeader>
        <band height="100">
            <staticText>
                <reportElement x="0" y="0" width="285" height="36"/>
                <textElement>
                    <font size="24" isBold="true"/>
                </textElement>
                <text><![CDATA[Report of Testing]]></text>
            </staticText>
        </band>
    </pageHeader>
    <detail>
        <band height="200">
            <staticText>
                <reportElement x="0" y="0" width="374" height="48"/>
                <textElement>
                    <font size="18"/>
                </textElement>
                <text><![CDATA[If you don't see this, it didn't work blah blah blah.... ]]></text>
            </staticText>
        </band>
    </detail>
    <pageFooter>
        <band height="100"/>
    </pageFooter>
</jasperReport>

I don't quite know about .jrxml, i got this sample from the web, if I made a mistake please correct it.

Source: http://www.iaeronz.com/?p=562

hendrakmg
  • 37
  • 7
  • You should add *itext-x.jar* to classpath. Check the pom.xml of *JasperReports library* (I don't know what version you are using) to get right dependencies (libs and its versions) – Alex K Mar 26 '13 at 15:12
  • the itext-2.0.8 already bundled with griffon 1.2.0. For jasperreport i use ver. 1.0.0. My concern is about this com/lowagie/text/SplitCharacter, something not right with that. here is the doc about the itext-2.0.8 class: http://www.jarvana.com/jarvana/view/com/lowagie/itext/2.0.8/itext-2.0.8-javadoc.jar!/index.html why that can't be found? – hendrakmg Mar 26 '13 at 15:22
  • The version *1.0.0* of *JasperReports* is using *itext-1.3.1.jar* – Alex K Mar 26 '13 at 17:23
  • i change it to itext-1.3.1.jar it's still give me error like above. What to do?Where is the source of problem? :( – hendrakmg Mar 27 '13 at 12:33
  • Do you have the same Exception: `java.lang.NoClassDefFoundError: com/lowagie/text/SplitCharacte`? – Alex K Mar 27 '13 at 12:45
  • yes, i have. you get that to? from the reference it's sould be there, why it can't be found? – hendrakmg Mar 30 '13 at 09:53
  • Hi, Alex K. I just try to run the program for past a few day, it didn't give me error like that again, i don't know why it's just like that. but i encounter the new error like: java.lang.NoSuchFieldError: APPDEFAULT, what does this mean? i just comment this line: JasperExportManager.exportReportToPdfFile(jasperPrint, "g:/sample.pdf") and the jasper report pop up showing, but when i save it to pdf the file is broken, i tried the other extension it just fine. is jasper can't save it as pdf file? – hendrakmg Apr 03 '13 at 04:22

0 Answers0