I'm trying to set color of four buttons in a loop. Therefore I've created an array with the buttons but everytime I try to set the color I get this compiler error. Besides the four Button are initialized in a another class.
Normally you get the error NullPointerException when you are trying to acces an object that is only declared and not initialized. But in my case I've already initialized the objects ("Button") in class buttonn.
Button[] button = {buttonn.a, buttonn.b, buttonn.c, buttonn.d};
for(int i = 0; i < button.length; i ++){
button[i].setBackground(Color.WHITE);
}
This is the class where the buttons are initialized:
public class buttonn {
...
public static buttona a;
a = new JButton;
a.setBounds(600, 500, 200, 50);
this.add(a);
...