This is the code I’m using to load an image called “boat.png”
@Override
public void paint(Graphics g) {
BufferedImage img = null;
try {
img = ImageIO.read(new File("boat.png"));
} catch (IOException e) {
System.out.println("Can't load the image");
}
}
These two lines generate errors
BufferedImage img = null;
img = ImageIO.read(new File("boat.png"));
Although I’ve included
import java.io.*;
import java.awt.*;
Please help me find the error !!
The ImageIO class is in the javax.imageio package.
Try importing that package: