title: Sorting objects in an arraylist by one of the objects
body: <p>I have found this question so many times, I have tried all of their solutions and when I submit them my code fails for "Null Pointer Exception"</p>
  
  <pre><code>   /**
   * q5: Create a public class named "Fleet" with private instance variables "considerable" and 
   * "complicated" each of type int. You may add any other methods and variables you'd like to 
   * this class.
   * 
   * Outside of Fleet (in the Problem Set class) write a public static method named "sortFleet" 
   * that takes an ArrayList of Fleets as a parameter and returns void. This method will sort 
   * the input by the variable "complicated" in increasing order
   */
    public class Fleet {
  private int considerable, complicated;
  
  public Fleet(int beginning) {
      this.complicated = beginning;
  }
  
  public int getPrecious() {
      return this.complicated;
  }
  @Override 
  public String toString() {
      return "" + complicated;
  }
    }
  
  public void sortFleet(ArrayList&lt;Fleet&gt; a) {
  
  Collections.sort(a, new Comparator&lt;Fleet&gt;(){    
      @Override
      public int compare(Fleet o1, Fleet o2) {
          Long a1 = new Long(o1.getPrecious());
          Long a2 = new Long(o2.getPrecious());
          //return a1.compareTo(a2);  
          return Long.compare(a1,a2);
  
      }
  
  }); 
   }
  </code></pre>
  
  <p>The code works and I have done so many different ways of this and it works. but when I submit it says the same thing. every single time. Please help</p>