线程“ Thread”中的异常; java.lang.OutOfMemoryError:请求的数组大小超出了VM限制 [英] Exception in thread "Thread" java.lang.OutOfMemoryError: Requested array size exceeds VM limit

查看:884
本文介绍了线程“ Thread”中的异常; java.lang.OutOfMemoryError:请求的数组大小超出了VM限制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

唯一的区别是有两个不同的作物位置。
问题是为什么我会收到此错误?

The only thing difference is there is two different crop location. The question is why i get this error??

方法调用

CropRealOriginalImage1 orderName = new CropRealOriginalImage1();
        FourAreaCropAgain1 orderNameFirst=new FourAreaCropAgain1();
        orderNameFirst.orderNameFirst();
        Decode decode= new Decode();
        decode.inputImage("C:/TEMP/Image/Embed Image/Four Area/OrderFirst.png");
        if(decode.s.equals("")){
            System.out.println("OderFirst=null");
        }else{
            //put b into txt file
            System.out.println("decode.s" +decode.s);
        }

工作:

  public void orderNameFirst(){
       ImageIcon icon = new ImageIcon("C:/TEMP/Image/Embed Image/Really Original.png");
    image = icon.getImage();
    image = createImage(new FilteredImageSource(image.getSource(),
        new CropImageFilter(icon.getIconWidth()-290, 0, 10, 33)));
            //new CropImageFilter(icon.getIconWidth()/2, icon.getIconHeight()/2, icon.getIconWidth()/2, icon.getIconHeight()/2)));

    BufferedImage bufferedImage = new BufferedImage(icon.getIconWidth(),
            icon.getIconHeight(), BufferedImage.TYPE_INT_RGB);
    Graphics graphics = bufferedImage.getGraphics();
    graphics.drawImage(icon.getImage(), 0, 0, null);

    Graphics2D g = bufferedImage.createGraphics();
    g.setColor(Color.WHITE);
    g.fillRect(icon.getIconWidth()-290, 0, 10, 33);

 }

不起作用

   public void orderNameFirst(){
        ImageIcon icon = new ImageIcon("C:/TEMP/Image/Embed Image/Really Original.png");
    image = icon.getImage();
    image = createImage(new FilteredImageSource(image.getSource(),
        new CropImageFilter(3*icon.getIconWidth()/8, 0, icon.getIconWidth()/8, icon.getIconHeight()/2)));
            //new CropImageFilter(icon.getIconWidth()/2, icon.getIconHeight()/2, icon.getIconWidth()/2, icon.getIconHeight()/2)));

    BufferedImage bufferedImage = new BufferedImage(icon.getIconWidth(),
            icon.getIconHeight(), BufferedImage.TYPE_INT_RGB);
    Graphics graphics = bufferedImage.getGraphics();
    graphics.drawImage(icon.getImage(), 0, 0, null);

    Graphics2D g = bufferedImage.createGraphics();
    g.setColor(Color.WHITE);
    g.fillRect(3*icon.getIconWidth()/8, 0, icon.getIconWidth()/8, icon.getIconHeight()/2);
   }

错误:解码整数长度:2147483647
线程 Thread中的异常java.lang.OutOfMemoryError:请求的数组大小超出了VM限制

Error: Decode integerLength: 2147483647 Exception in thread "Thread" java.lang.OutOfMemoryError: Requested array size exceeds VM limit

推荐答案

免责声明:这可能不是


问题是为什么我会收到此错误?

The question is why i get this error??

您收到错误:

 Exception in thread "Thread" java.lang.OutOfMemoryError: Requested array size exceeds VM limit

...因为您在尝试创建一个大于Java VM堆中最大连续内存块的数组。发生这种情况的原因可能是因为您试图创建一个巨大的映像,或者可能是您的VM在分配数组时通常只在资源不足的情况下运行。

...because you are trying to create an array that is larger than the maximum contiguous block of memory in your Java VMs heap. This can happen either because you are trying to create a humongously large image, or it could be that your VM is just generally running low on resources at the time you try to allocate the array.

这很可能发生在 BufferedImage 构造函数之一内部。

This most likely happens inside one of the BufferedImage constructors.

但是很难说,因为您还没有发布完整的堆栈跟踪信息,也没有发布有关图像尺寸或其他值的实际信息在运行时。

But it's hard to say, as you haven't posted the full stack trace, nor the relevant information about the images' sizes or other values actually passed around in your program at runtime.

此修复取决于内存不足的原因。

The fix depends on the reason for running out of memory.

例如,我从您的代码中看到,您从未在 dispose 您正在创建的> Graphics / Graphics2D 实例。随着时间的流逝,这很可能导致资源泄漏(仅举一个例子,可能还有其他情况)。

As an example, I can see from your code that you never invoke dispose on the Graphics/Graphics2D instances you are creating. This will likely cause a resource leak over time (just an example, there might be others).

如果由于图像巨大而立即耗尽内存,则需要增加最大堆大小。通常是通过将 -Xmx< value> 参数传递给 java 命令行(其中< value> 是新的最大大小,例如 256m 1G 或类似)。

If you just run out of memory immediately, because the image is huge, you need to increase the maximum heap size. This is typically done, by passing a -Xmx<value> argument to the java command line (where <value> is the new max size, like 256m, 1G or similar).

这篇关于线程“ Thread”中的异常; java.lang.OutOfMemoryError:请求的数组大小超出了VM限制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆