2011-11-10 45 views
0

在我的揮杆應用程序時,我要打印的Java堆空間,以下異常given.but並不總是像瞬間的時間。在碧玉報告中執行以下代碼時會發生這種情況。我該如何解決這個問題?java.lang.OutOfMemoryError:在JasperReports的

 
    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

[java.lang.OutOfMemoryError:jasper報告中的Java堆空間]的可能重複(http://stackoverflow.com/questions/1587098/java-lang-outofmemoryerror-java-heap-space-in-jasper-report ) –

回答

1

您可以使用JVM的-Xmx選項。 用更多的堆內存啓動你的應用程序。
例如

 
     java -Xmx512M YourClass 
+0

謝謝。如果我的應用程序打開後雙擊.jar,你會讓我知道如何使用'-Xmx'嗎? (不在cmd中運行) –

+0

你可以看看這個問題。 http://stackoverflow.com/questions/1018217/can-i-set-java-max-heap-size-for-running-from-a-jar-file – LoSciamano

1

簡單的解決方案是使用-Xmx JVM選項來增加堆大小。然而,你能做多少次/多少次是有限制的。

如果您已經使用不可接受的大量的內存,您將需要看您生成報告的方式。尤其是,您可能需要將報告分成較小的報告。

+0

非常感謝您爲您的信息。我仍然,你會讓我知道如何拆分報告嗎?另外我想在雙擊時運行我的jar。那麼在哪裏以及如何使用'Xmx'? –