0

In my swing application when I am going to print, following exception is given.but not always, like trice a time. it occurs when the following code is executed in jasper reporting. How can I solve this issue?

    Exception occurred during event dispatching:
    java.lang.OutOfMemoryError: Java heap space  
        JRBeanCollectionDataSource datasource = new JRBeanCollectionDataSource(purchasingList);
        JasperPrint jasperPrint = JasperFillManager.fillReport(in, params, datasource);

        if (view) {// using a JDialog a preview of the print is showed.
             new Shows().showJasper(jasperPrint, "Invoice No:" + invoiceNo);
        }

        final JRPrintServiceExporter exporter = new JRPrintServiceExporter();
        exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
//      exporter.setParameter(JRPrintServiceExporterParameter.DISPLAY_PAGE_DIALOG, Boolean.FALSE);
        exporter.setParameter(JRPrintServiceExporterParameter.DISPLAY_PRINT_DIALOG, Boolean.TRUE);
        exporter.exportReport();
mdahlman
  • 9,204
  • 4
  • 44
  • 72
Débora
  • 5,816
  • 28
  • 99
  • 171
  • 1
    possible duplicate of [java.lang.OutOfMemoryError: Java heap space in jasper report](http://stackoverflow.com/questions/1587098/java-lang-outofmemoryerror-java-heap-space-in-jasper-report) – Matthew Farwell Nov 10 '11 at 09:37

2 Answers2

1

You can use the -Xmx option of the JVM. Launch your application with more heap memory.
e.g.

      java -Xmx512M YourClass
LoSciamano
  • 1,099
  • 10
  • 21
  • Thanks. Would you let me know how to use `-Xmx` if my application is opened double clicking the .jar ? (not run in cmd) – Débora Nov 10 '11 at 09:48
  • You can take a look at this question. http://stackoverflow.com/questions/1018217/can-i-set-java-max-heap-size-for-running-from-a-jar-file – LoSciamano Nov 10 '11 at 09:52
1

The simple solution is to use the -Xmx JVM option to increase the heap size. However, there is a limit to how often / how much you can do that.

If you are already using an unacceptably large amount of memory, you will need to look at the way that you are generating the report. In particular, you may need to split it the report into smaller ones.

Stephen C
  • 698,415
  • 94
  • 811
  • 1,216
  • Thank you very much for your info. I m still, would you let me know how to split the report? Also I want to run my jar when it double clicked. then where and how to use `Xmx` ? – Débora Nov 10 '11 at 09:44