无法实例化Image java的类型? [英] Cannot instantiate the type Image java?
本文介绍了无法实例化Image java的类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
public Image images[] = new Image[20];
for(i=0; i<10; i++){
images[i]=new Image(getClass().getResource("/images/"+i+".jpg"));
}
我正在尝试将图像添加到数组但它给出了错误无法实例化类型图像j
I am trying to add images to array but it gives the error Cannot instantiate the type Image j
可能是什么原因?
推荐答案
摘要类不能直接实例化。您可以使用 ImageIO.read
返回 BufferedImage
,图像<的子类/ code>
Abstract classes cant be instantiated directly. You could use ImageIO.read
which returns BufferedImage
, a sub-class of Image
void loadImages() throws IOException {
for (int i = 0; i < 10; i++) {
images[i] = ImageIO.read(getClass().getResource("/images/" + i + ".jpg"));
}
}
这篇关于无法实例化Image java的类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文