Netbeans中的Jasperviewer:java.lang.OutOfMemoryError:Java堆空间

时间:2009-09-12 17:21:08

标签: java

当我在Netbeans 6.5中执行项目时,在查看报告(jasper报告)时,jasperviewer会打开,但不完整。并在输出窗口中抛出异常,如下所示:

Exception occurred during event dispatching:
java.lang.OutOfMemoryError: Java heap space
    at java.awt.image.DataBufferByte.<init>(DataBufferByte.java:58)
    at java.awt.image.ComponentSampleModel.createDataBuffer(ComponentSampleModel.java:397)
    at java.awt.image.Raster.createWritableRaster(Raster.java:938)
    at javax.imageio.ImageTypeSpecifier.createBufferedImage(ImageTypeSpecifier.java:1169)
    at javax.imageio.ImageReader.getDestination(ImageReader.java:2879)
    at com.sun.imageio.plugins.jpeg.JPEGImageReader.readInternal(JPEGImageReader.java:943)
    at com.sun.imageio.plugins.jpeg.JPEGImageReader.read(JPEGImageReader.java:915)
    at javax.imageio.ImageIO.read(ImageIO.java:1422)
    at javax.imageio.ImageIO.read(ImageIO.java:1326)
    at net.sf.jasperreports.engine.util.JRJdk14ImageReader.readImage(JRJdk14ImageReader.java:58)
    at net.sf.jasperreports.engine.util.JRImageLoader.loadImage(JRImageLoader.java:248)
    ....

4 个答案:

答案 0 :(得分:3)

给自己更多的堆空间:

java -Xmx512m ...

表示512M,依此类推。

Netbeans会为您提供一个指定VM参数的选项(其中-Xmx是影响内存使用的参数)。

另一条建议:如果您正在使用Jasper Reports的bean shell编译器,请不要这样做。这是一个巨大的记忆力,而且很慢。确保使用JDT编译器。

答案 1 :(得分:0)

尝试将JVM参数添加到Project运行时设置以增加可用堆空间量; e.g。

-mx256M

...会将可用堆增加到256 MB。

答案 2 :(得分:0)

要获得永久性解决方案,请尝试使用分析器分析您的应用程序。请检查此链接here

答案 3 :(得分:0)

我喜欢使用visualgc来查看内存不足时发生的情况。 VisualGC将帮助您查看内存的哪个部分实际上是问题。

以下是关于如何在netbeans中设置内存参数的问题的片段。

http://www.experts-exchange.com/Programming/Languages/Java/Q_21039388.html

It's been a while since I used netbeans but there is a file that is called ide.cfg

Here you can edit the line:
        -J-Xverify:none -J-Xms24m -J-Xmx96m

and make the -J-Xmx parameter to be 128 Mb like this:

        -J-Xverify:none -J-Xms24m -J-Xmx128m

On a more gerneral note: It's probably more efficient to look at the memory usage of your app. If it's doing this during development your are going to have fun with this app in production...