Java - NullPointerException after initializing array and when testing array with class method

后端 未结 4 1185
借酒劲吻你
借酒劲吻你 2021-01-13 10:26

I\'ve been trying to initialize an array and then test its values with a class method. I have initialized the array and have already tested it successfully within the constr

4条回答
  •  礼貌的吻别
    2021-01-13 11:05

    In the constructor you initialize an array boolean[]. The array is only visible in the constructor. If you want to use the array of the class, then replace

    boolean[] grid = new boolean[sides];
    

    with

    grid = new boolean[sides];
    

    . Then you use the array of the class, not of the constructor.

提交回复
热议问题