I want to compare two icons (one is the icon set to the button and the other is an image icon declared just above the if statement. Java gives me null pointer exception for the comparison. what's the problem? (Is it a syntax error? am I using an incorrect method for comparing the icons?)
final ImageIcon x=new ImageIcon("X.png");
final ImageIcon o=new ImageIcon("O.png");
if(jbutton[0][0].getIcon().equals(x)&& jbutton [1][0].getIcon().equals(x)&& jbutton[2][0].getIcon().equals(x))
{
JOptionPane.showMessageDialog(null, "insert message here");
hasWinner=(true);
}
else if (jbutton[0][1].getIcon().equals(x)&& jbutton [1][1].getIcon().equals(x)&& jbutton[2][1].getIcon().equals(x))
{
JOptionPane.showMessageDialog(null, "insert message here");
hasWinner=(true);
}