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 が表示されます
その理由は何ですか?
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
ある which returnsを使用できますBufferedImage
Image
void loadImages() throws IOException {
for (int i = 0; i < 10; i++) {
images[i] = ImageIO.read(getClass().getResource("/images/" + i + ".jpg"));
}
}
Image
は抽象クラスであるため、インスタンス化できません。またはImage
のように拡張するクラスのいずれかを使用する必要があります。BufferedImage
VolatileImage
出典: Image の Javadoc