I write tic tac toe and i have small problem.
When checking the fields, console write error:
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at pl.knugi.Main.sprawdzKombinacje(Main.java:164)
at pl.knugi.Main.actionPerformed(Main.java:179)
This code:
public boolean sprawdzKombinacje(String p){
String[] spr = new String[3];
for(JButton[] c : check){
int a = 0;
for(JButton b : c){
spr[a]=b.getText();
a++;
}
if(spr[0].equals(p)&&spr[1].equals(p)&&spr[2].equals(p)){
return true;
}
}
return false;
}
Variables:
JButton[] check1 = {button1, button2, button3};
JButton[] check2 = {button4, button5, button6};
JButton[] check3 = {button7, button8, button9};
JButton[] check4 = {button1, button4, button7};
JButton[] check5 = {button2, button5, button8};
JButton[] check6 = {button3, button6, button9};
JButton[] check7 = {button1, button5, button9};
JButton[] check8 = {button3, button5, button7};
JButton[][] check = {check1, check2, check3, check4, check5, check6, check7, check8};
What am i doing wrong?
Problem is b.getText(), because this is AbstractButton. Then how I getted text from my button ?