Reputation: 5952
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();
Upvotes: 0
Views: 2783
Reputation: 718768
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.
Upvotes: 1
Reputation: 1119
You can use the -Xmx
option of the JVM.
Launch your application with more heap memory.
e.g.
java -Xmx512M YourClass
Upvotes: 1