I have the following test class Test_Retina that is testing a method in a class Retina called "seeBMPImage" by first retrieving a .bmp image. However I am getting a null pointer exception and I don't understand why because a image 66 by 66 pixels wide is named "2.bmp" and it is in the same package as classes "Retina.java" and "Test_Retina.java"
public class Test_Retina extends junit.framework.TestCase {
private Retina retina;
public void setUp() {
VisionCell[][] visionCells = new VisionCell[66][66];
// this.retina = new Retina(visionCells);
}
public void test_seeBMPImage() throws IOException {
this.retina.seeBMPImage("2.bmp"); <-- !!GETTING A NULLPOINTEREXCEPTION!!
// ...
}
}
public class Retina {
private VisionCell[][] visionCells;
public void seeBMPImage(String BMPFileName) throws IOException {
BufferedImage image = ImageIO.read(getClass().getResource(BMPFileName));
int color = image.getRGB(1, 1);
if (color == Color.BLACK.getRGB()) {
System.out.println("black");
} else {
System.out.println("white");
}
}
}