static JPanel fieldPanel = new JPanel();
static char cell[][][] = new char[2][12][12];
static JButton jCell[][][] = new JButton[2][12][12];
public void initField(){
for (int y=1; y<11; y++){
for (int field=0; field<2; field++ ){
for (int x=1; x<11; x++){
cell[field][x][y] = '.';
jCell[field][x][y].setBounds((x * 20) + (field * 200), y * 20, 15, 15);
fieldPanel.add(jCell[field][x][y]);
}
}
}
}
线程“main”中的异常 java.lang.NullPointerException 位于最长的字符串/
最佳答案
您需要像下面一样创建 JButton,然后您可以设置边界。
jCell[field][x][y] = new JButton();
jCell[field][x][y].setBounds((x * 20) + (field * 200), y * 20, 15, 15);
关于java - 无法获取异常原因。谁能给我线索吗?那里的空值在哪里?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21287577/