title: Mutator methods with an Array of Objects in Java
body: <p>So i have an array of Room objects, the reason its static is because I'm doing it in main.</p>
  
  <pre><code>private static Room[] rooms = new Room[6];
  </code></pre>
  
  <p>So in my room class, i have a method called setStatus which sets a string to the room object</p>
  
  <pre><code>public String setStatus(String answer) {
  if (answer.equalsIgnoreCase("Available") || answer.equalsIgnoreCase("Occupied")
              || answer.equalsIgnoreCase("Needs cleaning (unavailable)")
              || answer.equalsIgnoreCase("For walk-ins")
              || answer.equalsIgnoreCase("For emergencies")) {
          this.status = answer;
          return status;
      } else {
          System.out.println("Status must be set to Available, Occupied or Needs cleaning (unavailable)");
          return null;
      }
  
  }//end of setStatus
  </code></pre>
  
  <p>Now i want to set the status for each position in the array</p>
  
  <pre><code>rooms[random.nextInt(6)].setStatus("For walk-ins");
  </code></pre>
  
  <p><strong>However i get a nullpointer exception when i set the status of the array, any ideas?.</strong></p>