title: NPE when trying to access variable from a method. Processing/Java
body: <p>I'm trying to make a Grid Class to use in a Sketch I want to make (I'm using Processing) but I get a NullPointerException when trying to access the grid variable from a method printGrid() of the Grid Class.</p>
  
  <p>Code:</p>
  
  <p><strong>Grid_Proj:</strong></p>
  
  <pre><code>Grid gridObj;
  
  void setup() {
    size(480, 360);
    background(0);
  
    gridObj = new Grid(10, 10);
  
    gridObj.printGrid();
  }
  </code></pre>
  
  <p><strong>Grid:</strong></p>
  
  <pre><code>class Grid {
  
    int[][] grid;                               // Declare the Grid
  
    Grid(int size_x, int size_y) {
  
      int grid[][] = new int[size_x][size_y];   // Initialize the Grid
  
      for (int x=0;x&lt;size_x;x++) {
        for (int y=0;y&lt;size_y;y++) {
          grid[x][y] = 0;
        }
      }
  
      println("Created Grid Object with: ", size_x, size_y);
    }
  
    void printGrid() {
  
      for (int x=0;x&lt;10;x++) {
        for (int y=0;y&lt;10;y++) {
          print(grid[x][y]);     // NPE Error here
        }
        print('\n');
      }
    }
  }
  </code></pre>
  
  <p>I'm obviously doing something wrong here, but I can't figure out what.
  I also tried using</p>
  
  <pre><code>this.grid[x][y]
  </code></pre>
  
  <p>to no avail.</p>