2

So for my 2D game I want to use an image to represent a player but when I try to use an image, it tells me that it couldn't be "instantiated". I don't know what that means:

public class PlayerOne extends Entity{
  private Image img = new Image();
[...]
  @Override
  public void render(Graphics g){
  g.drawImage( img , x, y, Color.BLUE, new ImageObserver());
  }
}

I tried it in another class with BufferedImages but that somehow doesn't work.

So it can't create Objects of neither Image nor the ImageObserver. Does anyone know a fix for this error ?

Puck
  • 2,080
  • 4
  • 19
  • 30
Toreole
  • 33
  • 1
  • 10
  • 1
    "The abstract class Image is the superclass of all classes that represent graphical images. The image must be obtained in a platform-specific manner." – Marvin Jan 12 '16 at 20:23

2 Answers2

2

You cannot instantiate an abstract class. Please see link.

Following syntax would be operational:

private Image image = new BufferedImage(200,200,BufferedImage.TYPE_INT_RGB);

Also see link for more information on BufferedImage. Additionally, here is a tutorial which ilustrates an example implementation;

e.doroskevic
  • 2,129
  • 18
  • 25
1

You should have an image file (*.png for example ) to start with. Then use

Image  img = new ImageIcon("img.png").getImage();
SomeDude
  • 13,876
  • 5
  • 21
  • 44