public Image images[] = new Image[20];
for(i=0; i<10; i++){
images[i]=new Image(getClass().getResource("/images/"+i+".jpg"));
}
我正在尝试将图像添加到数组,但出现错误 Cannot instantiate the type Image j
可能是什么原因?
抽象类不能直接实例化。你可以使用ImageIO.read http://docs.oracle.com/javase/7/docs/api/javax/imageio/ImageIO.html#read%28java.net.URL%29返回BufferedImage
,一个子类Image
void loadImages() throws IOException {
for (int i = 0; i < 10; i++) {
images[i] = ImageIO.read(getClass().getResource("/images/" + i + ".jpg"));
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)