title: Passing a 2d array from one method to another
body: <p>Programming language: Java</p>
  
  <p>editor: Vim</p>
  
  <p>I been trying to do an assignment that includs a 2d array. I've been struggling on it pretty bad since this is the second time I've used any kind of arrays. Anyway, i just got some questions that I hope someone here can clear up for me.</p>
  
  <p>1) is this is how you would pass a double array to another method? </p>
  
  <p>this is my boolean array:</p>
  
  <pre><code>boolean[][] TempGrid = new boolean[GRIDSIZE][GRIDSIZE];
  </code></pre>
  
  <p>this is how I have been trying to pass it.</p>
  
  <pre><code>countNeighbors(TempGrid[][]);
  </code></pre>
  
  <p>this is method accepting the array:</p>
  
  <pre><code> public static int countNeighbors ( final boolean[][] grid, final int row, final int col )
  </code></pre>
  
  <p>however, when I compile i get an error saying:</p>
  
  <pre><code>error: '.class' expected
       countNeighbors(TempGrid[][]);
                                  ^
  1 error
  </code></pre>
  
  <p>I did some research on the .class error like:</p>
  
  <p>-<a href="http://www.daniweb.com/software-development/java/threads/213357/pass-2-dimensional-array-into-method" rel="nofollow">http://www.dreamincode.net/forums/topic/70299-class-expected-error/</a></p>
  
  <p>-<a href="http://www.daniweb.com/software-development/java/threads/213357/pass-2-dimensional-array-into-method" rel="nofollow">http://stackoverflow.com/questions/12309220/class-error-in-java-applet</a></p>
  
  <p>-<a href="http://www.daniweb.com/software-development/java/threads/213357/pass-2-dimensional-array-into-method" rel="nofollow">http://www.daniweb.com/software-development/java/threads/213357/pass-2-dimensional-array-into-method</a></p>
  
  <p>and various other sites/forums. The solution they presented either didn't work or cause more issues with my program.</p>
  
  <p>btw this is the entire method:</p>
  
  <pre><code> public static void genNextGrid ( boolean[][] grid )
  {
  
       boolean[][] TempGrid = new boolean[GRIDSIZE][GRIDSIZE];
  
       TempGrid[GRIDSIZE][GRIDSIZE] = grid[GRIDSIZE][GRIDSIZE];
  
       countNeighbors(TempGrid);
  
      for(int row = 1; row &lt; 18; row++)
  {
  
          countNeighbors(row);
  
          for(int col = 1; col &lt; 18; col++)
  {
  
              countNeighbors(col);
  
              if(n == 3)
              {
                  TempGrid[row][col] = true;
              }
              else if(n == 2 || n == 3)
              TempGrid[row][col] = true;
              }
              else
              {
                  TempGrid[row][col] = false;
              }
  
          }
      }
  
  
  }
  </code></pre>
  
  <p>I've attempted in removing <code>[][]</code> from <code>countNeighbors(TempGrid[][]);</code> so it would look like: </p>
  
  <pre><code>countNeighbors(TempGrid);
  </code></pre>
  
  <p>but gave me 3 errors</p>
  
  <pre><code> error: method countNeighbors in class Life cannot be applied to given types;
       countNeighbors(TempGrid);
       ^
   required: boolean[][],int,int
  found: boolean[][]
  reason: actual and formal argument lists differ in length
  
  
  error: method countNeighbors in class Life cannot be applied to given types;
          countNeighbors(row);
          ^
  required: boolean[][],int,int
  found: int
  reason: actual and formal argument lists differ in length
  
  
   error: method countNeighbors in class Life cannot be applied to given types;
              countNeighbors(col);
              ^
    required: boolean[][],int,int
   found: int
   reason: actual and formal argument lists differ in length
  </code></pre>
  
  <p>-Thanks for your help in advance</p>