Error generating JasperReport in development mode

I have a problem initializing the report in the program at startup. This once worked correctly. But when I unistall JDK 1.7 update 17 to update JDK 1.7 21 and update Netbeans, there is an Exception: (

This error message is:

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 the 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()); } } 

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

Please help, thanks before :)

+4
source share
3 answers

Do you use Calibri font? I found that this is a jdk 1.7.0_21 error and seems to apply to Calibri. Try switching the font to Arial and the error should go away.

If you have many reports and subreports for change, this may help:

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

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

Debugging the application, I see that createCharinfo receives a StandardGlyphVector object and requests it for the number of glyphs that returns 0. StandardGlyphVector.getGlyphCharIndices (0,0, null) then returns a non-zero but empty array. The code sun.font.ExtendedTextSourceLabel does not check for errors with an empty or empty array and tries to access an array that AIOOBE throws correctly.

There seems to be a related bug report here .

+4
source

I also ran into this problem and did a bit more testing on this . The findings here are brief, but I also commented on the OTN stream .

  • performed by the JVM version 1.6.0u45 and 1.7.0u21
  • performed only by Calibri, Calibri Bold, Calibri Bold Italic, Calibri Italic and Cambria Bold fonts.
  • Most likely fixed in non-public version 1.6.0u51
  • fixed in 1.7.0u25
+3
source

We upgraded our jdk from version b24 to version b27 version 1.6.

As we discovered the same problem, we fixed the font changes as follows:

In the iReport designer, for any element, if we do not specify the font properties (fontName and fontSize), it will be installed by default. Hope this created a problem.

So, we “specified the font properties (esp. FontName) for each element in each of our reports” and tried. This fixed the problem.

Root reason as expected: In older versions of jdk, the font manager handles the default properties for elements where the font property is not specified. In recent versions, jdk cannot handle font properties by default.

0
source

All Articles