Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/391.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
&引用;图像动画师3“;java.lang.OutOfMemoryError:java堆空间_Java_Out Of Memory - Fatal编程技术网

&引用;图像动画师3“;java.lang.OutOfMemoryError:java堆空间

&引用;图像动画师3“;java.lang.OutOfMemoryError:java堆空间,java,out-of-memory,Java,Out Of Memory,我正在编写一个Java程序,最近我在其中添加了一个.GIF图像。代码如下: package rtype; import java.awt.Image; import java.util.Random; import javax.swing.ImageIcon; public class Alien extends RType { private Image aliens; private int x; private int y; private boolean visible; priva

我正在编写一个Java程序,最近我在其中添加了一个.GIF图像。代码如下:

package rtype;
import java.awt.Image;
import java.util.Random;
import javax.swing.ImageIcon;

public class Alien extends RType {

private Image aliens;
private int x;
private int y;
private boolean visible;
private String type;
private ImageIcon ii;

public Alien(String type) {

    this.type = type;

    if ("Normal".equals(type)) {
        ii = new ImageIcon(this.getClass().getResource("alien_normal.gif"));
    } else if ("Rapid".equals(type)) {

//before adding this line all things are OK!


        ii = new ImageIcon(this.getClass().getResource("alien_rapid.gif"));   
    }

    aliens = ii.getImage();
    Random rnd = new Random();
    x = rnd.nextInt(328) + 15;
    y = 0;
    visible = true;

}

public void move() {

    if ("Normal".equals(this.type)) {
        y += 1;
    } else if ("Rapid".equals(this.type)) {
        y += 2;
    }

    if (y > 530) {
        visible = false;
    }
}

public Image getImage() {
    return aliens;
}


@Override
public int getX() {
    return x;
}

@Override
public int getY() {
    return y;
}

@Override
public boolean isVisible() {
    return visible;
}

@Override
public void setVisible(boolean i) {
    visible = i;
}

}
但现在抛出以下错误:

Exception in thread "Image Animator 3" java.lang.OutOfMemoryError: Java heap space
at java.awt.image.IndexColorModel.<init>(IndexColorModel.java:338)
at sun.awt.image.GifImageDecoder.readImage(GifImageDecoder.java:526)
at sun.awt.image.GifImageDecoder.produceImage(GifImageDecoder.java:212)
at sun.awt.image.InputStreamImageSource.doFetch(InputStreamImageSource.java:269)
at sun.awt.image.ImageFetcher.fetchloop(ImageFetcher.java:205)
at sun.awt.image.ImageFetcher.run(ImageFetcher.java:169)
线程“Image Animator 3”java.lang.OutOfMemoryError中出现异常:java堆空间 位于java.awt.image.IndexColorModel(IndexColorModel.java:338) 位于sun.awt.image.GifImageDecoder.readImage(GifImageDecoder.java:526) 位于sun.awt.image.GifImageDecoder.produceImage(GifImageDecoder.java:212) 位于sun.awt.image.InputStreamImageSource.doFetch(InputStreamImageSource.java:269) 位于sun.awt.image.ImageFetcher.fetchloop(ImageFetcher.java:205) 运行(ImageFetcher.java:169) 我想应该注意的是,我用一个在线工具重新收集了alien_normal.gif,以生成我的alien_rapid.gif
提前谢谢你

338行是哪一行?这只是model/bean类,其中是main方法,这里是main方法,但问题在于该类本身。包装rtype;导入javax.swing.JFrame;公共类RType扩展了JFrame{public RType(){add(new Board());setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);setSize(400600);setLocationRelativeTo(null);setTitle(“星球大战”);setResizeable(false);setVisible(true);}publicstaticvoidmain(String[]args){RType RType=new RType();}}}以及重新绘制的gif有多大?关键是,重新绘制的图像不大,但大小与原始图像相同!