在开发模式下生成JasperReport时出错 [英] Error generating JasperReport in Development mode

查看:90
本文介绍了在开发模式下生成JasperReport时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在启动时在程序中初始化报告时遇到问题。
前一段时间,它可以正常工作。但是当我将JDK 1.7更新17解除对JDK 1.7更新21以及全新安装Netbeans时,存在异常:(

i have problem when initialize report in program at startup. Sometime ago, it works correctly. But when i unistall JDK 1.7 update 17 to JDK 1.7 update 21, and fresh install Netbeans , the Exception exist :(

这是错误消息:

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
    at sun.font.ExtendedTextSourceLabel.createCharinfo(ExtendedTextSourceLabel.java:609)
    at sun.font.ExtendedTextSourceLabel.getCharinfo(ExtendedTextSourceLabel.java:509)
    at sun.font.ExtendedTextSourceLabel.getLineBreakIndex(ExtendedTextSourceLabel.java:455)
    at java.awt.font.TextMeasurer.calcLineBreak(TextMeasurer.java:325)
    at java.awt.font.TextMeasurer.getLineBreakIndex(TextMeasurer.java:561)
    at java.awt.font.LineBreakMeasurer.nextOffset(LineBreakMeasurer.java:358)
    at net.sf.jasperreports.engine.fill.SimpleTextLineWrapper.measureExactLineBreakIndex(SimpleTextLineWrapper.java:561)
    at net.sf.jasperreports.engine.fill.SimpleTextLineWrapper.measureExactLine(SimpleTextLineWrapper.java:535)
    at net.sf.jasperreports.engine.fill.SimpleTextLineWrapper.nextLine(SimpleTextLineWrapper.java:517)
    at net.sf.jasperreports.engine.fill.TextMeasurer.renderNextLine(TextMeasurer.java:649)
    at net.sf.jasperreports.engine.fill.TextMeasurer.renderParagraph(TextMeasurer.java:454)
    at net.sf.jasperreports.engine.fill.TextMeasurer.measure(TextMeasurer.java:395)
    at net.sf.jasperreports.engine.fill.JRFillTextElement.chopTextElement(JRFillTextElement.java:541)
    at net.sf.jasperreports.engine.fill.JRFillTextField.prepare(JRFillTextField.java:641)
    at net.sf.jasperreports.engine.fill.JRFillElementContainer.prepareElements(JRFillElementContainer.java:331)
    at net.sf.jasperreports.engine.fill.JRFillBand.fill(JRFillBand.java:379)
    at net.sf.jasperreports.engine.fill.JRFillBand.fill(JRFillBand.java:353)
    at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillBandNoOverflow(JRVerticalFiller.java:458)
    at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillPageHeader(JRVerticalFiller.java:421)
    at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReportStart(JRVerticalFiller.java:282)
    at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReport(JRVerticalFiller.java:151)
    at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:909)
    at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:822)
    at net.sf.jasperreports.engine.fill.JRFiller.fill(JRFiller.java:61)
    at net.sf.jasperreports.engine.JasperFillManager.fill(JasperFillManager.java:446)
    at net.sf.jasperreports.engine.JasperFillManager.fill(JasperFillManager.java:276)
    at net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:745)
    at com.ikbiz.gastroscope.controller.ReportController.initReport(ReportController.java:180)
    at com.ikbiz.gastroscope.controller.ReportController.<init>(ReportController.java:111)
    at com.ikbiz.gastroscope.view.PanelScope.<init>(PanelScope.java:32)
    at com.ikbiz.gastroscope.view.PanelEntry.initComponents(PanelEntry.java:199)
    at com.ikbiz.gastroscope.view.PanelEntry.<init>(PanelEntry.java:86)
    at com.ikbiz.gastroscope.view.Application.initComponents(Application.java:203)
    at com.ikbiz.gastroscope.view.Application.<init>(Application.java:35)
    at com.ikbiz.gastroscope.view.Application.getInstance(Application.java:43)
    at com.ikbiz.gastroscope.view.Application.main(Application.java:79)
Java Result: 1

这是我的初始化报告的代码。

And this is my code to initialize report.

public void initReport() {
        try {
            param.put("noMr", "0000");
            param.put("visitCode", "V-199208300000");
            param.put("templateLoco", iReportDir);
            param.put("tools", "Tools");
            param.put("medicine", "Medicine");
            param.put("result", "Data hasil disini");
            param.put("conclusion", "Data kesimpulan disini");
            param.put("suggestion", "Suggestion");
            param.put("SUBREPORT_DIR",iReportDir);

            String imageLoco = iReportDir +"image-sample.jpg";
            for (int i = 0; i < 20; i++) {        
                FileInputStream image = new FileInputStream(imageLoco);
                param.put("imgResult"+(i+1), image);
            }

            param.put("emptyImg", iReportDir+"logo.jpg");

            setTemplate("data/reports/templates/template_1.jasper");

            jasperPrint = JasperFillManager.fillReport(getTemplate(), param, DatabaseUtility.getConnection());
        } catch (JRException ex) {
            System.out.println(ex.getMessage());
        } catch (IOException ioe) {
            System.out.println(ioe.getMessage());
        }
    }

但是,当我构建时,和。 Jar,错误消失了。

But, the And when I build to. Jar, the error disappears.

请帮助,谢谢之前:)

推荐答案

您使用的是Calibri字体吗?我发现这是一个jdk 1.7.0_21错误,似乎特定于Calibri。
尝试将字体切换为Arial,错误应该消失。

Are you using the Calibri font? I've found that this is a jdk 1.7.0_21 bug and seems to be specific to Calibri. Try switching the font to Arial and the error should go away.

如果要修改大量报告和子报告,这可能会有所帮助:

If you have lots of reports and subreports to modify, this might help:

find . *.jrxml -type f -print0 |xargs -0 grep -lZ "Calibri" |xargs -0 sed -i 's/Calibri/Arial/g' 

我有一个应用程序也调用相同的JasperFillManager方法,我可以确认在jdk 1.7_0_21中看到相同的堆栈跟踪。如果我将jdk更改为1.7_0_17或1.7_0_07,则不会发生错误。
该类位于rt.jar中,据我所知,源代码不可用。但1.7基于openjdk,可以在 jdk7src 找到非常相似的来源。

I have an application that also calls into the same JasperFillManager method and I can confirm that I see the same stacktrace in jdk 1.7_0_21. If I changing the jdk to 1.7_0_17 or 1.7_0_07 the error does not occur. The class is in the rt.jar and as far as I know, source is not available. But 1.7 was based on openjdk and very similar source can be found at jdk7src.

调试应用程序,我可以看到createCharinfo获取一个StandardGlyphVector对象并查询它的字形数,返回0. StandardGlyphVector.getGlyphCharIndices(0,0,null)然后返回一个非null但是空数组。 sun.font.ExtendedTextSourceLabel代码不检查null或空数组返回情况,并尝试访问正确抛出AIOOBE的数组。

Debugging the application, I can see that createCharinfo gets a StandardGlyphVector object and queries it for the number of glyphs, which returns 0. StandardGlyphVector.getGlyphCharIndices(0,0,null) then returns a non-null but empty array. The sun.font.ExtendedTextSourceLabel code doesn't check for null or empty array return cases and tries to access into the array which correctly throws the AIOOBE.

似乎有相关错误报告此处

这篇关于在开发模式下生成JasperReport时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆