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();
1

2 Answers 2

1

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

      java -Xmx512M YourClass
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks. Would you let me know how to use -Xmx if my application is opened double clicking the .jar ? (not run in cmd)
You can take a look at this question. stackoverflow.com/questions/1018217/…
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.

1 Comment

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 ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.