javaswingimageicon

Adding an image in Java


I am getting an error: Image is abstract; cannot be instantiated in line 39. In line 45, the error cannot find symbol.

enter image description here


Solution

  • Since all the previous answers didnt mention that java.awt.Image is actually an abstract class that cannot be instantiated, well i had to interfere! the is the best way to create an Image.

    BufferedImage img = null;
    try {
        img = ImageIO.read(new File("strawberry.jpg"));
    } catch (IOException e) {
    }
    

    oh yah not to mention that gun1 object isnt defined in drawGun(Graphics2D g) method...