title: Cannot add to my List, throws a NullPointerException
body: <p>What im trying to do, I think, is fairly simple, but then I come from a PHP Background (you know, where most of the heavy lifting is done with and for you).</p>
  
  <p>basically, heres my log:</p>
  
  <pre><code>12-06 15:45:18.282: D/MAPVIEW(32047): Matching Providers are: [network, gps]
  12-06 15:45:18.282: D/MAPVIEW(32047): Um, whats the best provder? Well its obviously 'network'
  12-06 15:45:18.753: D/MAPVIEW(32047): Location Data: Lat:49, Long: -116
  12-06 15:45:18.753: D/MAPVIEW(32047): Could not add coordinate array to List, Error: java.lang.NullPointerException
  12-06 15:45:18.753: D/MAPVIEW(32047): Location Data: Lat:50, Long: -116
  12-06 15:45:18.753: D/MAPVIEW(32047): Could not add coordinate array to List, Error: java.lang.NullPointerException
  12-06 15:45:18.753: D/MAPVIEW(32047): Location Data: Lat:49, Long: -117
  12-06 15:45:18.753: D/MAPVIEW(32047): Could not add coordinate array to List, Error: java.lang.NullPointerException
  12-06 15:45:18.753: D/MAPVIEW(32047): Location Data: Lat:49, Long: -115
  12-06 15:45:18.753: D/MAPVIEW(32047): Could not add coordinate array to List, Error: java.lang.NullPointerException
  12-06 15:45:18.753: D/MAPVIEW(32047): Location Data: Lat:49, Long: -117
  12-06 15:45:18.753: D/MAPVIEW(32047): Could not add coordinate array to List, Error: java.lang.NullPointerException
  12-06 15:45:18.753: D/MAPVIEW(32047): Location Data: Lat:49, Long: -117
  12-06 15:45:18.763: D/MAPVIEW(32047): Could not add coordinate array to List, Error: java.lang.NullPointerException
  12-06 15:45:18.763: D/MAPVIEW(32047): Location Data: Lat:50, Long: -115
  12-06 15:45:18.763: D/MAPVIEW(32047): Could not add coordinate array to List, Error: java.lang.NullPointerException
  12-06 15:45:18.763: D/MAPVIEW(32047): Location Data: Lat:49, Long: -116
  12-06 15:45:18.763: D/MAPVIEW(32047): Could not add coordinate array to List, Error: java.lang.NullPointerException
  12-06 15:45:18.763: D/MAPVIEW(32047): Location Data: Lat:50, Long: -118
  12-06 15:45:18.763: D/MAPVIEW(32047): Could not add coordinate array to List, Error: java.lang.NullPointerException
  12-06 15:45:18.763: D/MAPVIEW(32047): Location Data: Lat:49, Long: -114
  12-06 15:45:18.783: D/MAPVIEW(32047): Could not add coordinate array to List, Error: java.lang.NullPointerException
  12-06 15:45:18.783: D/AndroidRuntime(32047): Shutting down VM
  12-06 15:45:18.783: W/dalvikvm(32047): threadid=1: thread exiting with uncaught exception (group=0x4001d5a0)
  </code></pre>
  
  <p>You will see that I'm trying to add to a list of coordinates, and the try catch is catching the exception. 
  ( Don't worry about the crash for now tho! I'll get to that. )</p>
  
  <p>So without much further adeu, heres my relevant code:</p>
  
  <pre><code>package com.private.clientndablocked;
  
  // ... imports
  
  public class ShowMapView extends MapActivity {
  
      // ... some initializers
      List&lt;int[]&gt; allLocations;
  
  
      @Override
      protected boolean isRouteDisplayed() {
          return false;
      }
  
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
  
          // .. whole bunch of other unreleated stuff
  
  
  
          // A single json object, this gets populated with cherry picked json array items
          JSONObject obj = null;
  
          // go through each of the items in the json array
          for(int i = 0; i &lt; json.length(); i++) {
  
              try {
                  // We must try to get the object first
                  obj = (JSONObject) json.get(i);
              } catch (JSONException e) {
  
                  e.printStackTrace();
              }
  
              // Initialize temp data with defaults
              int Latitude = 0;
              int Longitude = 0;
              String Title = "";
              String ID = "";
              int[] coords = new int[2];
  
              // So we actually have a picked item?
              if(obj != null)
                  try {
  
                      // Lets try to assign the temp vars with their real data
                      Latitude = (int) (obj.getDouble("lat") * 1e6);
                      Longitude = (int) (obj.getDouble("long") * 1e6);
                      Title = (String) (obj.getString("title"));
                      ID = (String) (obj.getString("id"));
  
  
                      // Save the lat and long of the new location data (non micro) 
                      // This stuff goes into allLocations List
                      coords[0] = obj.getInt("lat");
                      coords[1] = obj.getInt("long");
  
                  } catch (JSONException e) {
                      e.printStackTrace();
                  }
  
              // Create a new GeoPoint to store the microdegrees into
              GeoPoint point = new GeoPoint(
                  Latitude, 
                  Longitude
              );
  
              // Create a new OverlayItem with the GeoPoint and a title and snippet
              OverlayItem overlayitem = new OverlayItem(
                  point, 
                  Title, 
                  ID
              );
  
              itemizedoverlay.addOverlay(overlayitem);
              mapOverlays.add(itemizedoverlay);
  
              Log.d("MAPVIEW", "Location Data: Lat:" + coords[0] + ", Long: " + coords[1] );
  
              try{
                  allLocations.add(coords); // ************* this is whats failing ******************
              } catch(Exception e) {
                  Log.d("MAPVIEW", "Could not add coordinate array to List, Error: " + e.toString());
              }
  
  
  
          }
  
          // ... whole bunch more unrelated stuff
  
  
  }
  </code></pre>
  
  <p>Now the only thing that gets a little different is when i add</p>
  
  <pre><code>allLocations = Arrays.asList();
  </code></pre>
  
  <p>above the big for loop json extractor. This then makes the program throw UnsupportedOperationException. </p>
  
  <p>So honestly, i'm not sure what else to do. ..</p>
  
  <p>I thought I had Lists figured out, but evidently I do not :(</p>
  
  <p>(ps: I want to store these like this so i can do this:</p>
  
  <pre><code>int minLat = Integer.MAX_VALUE;
  int maxLat = Integer.MIN_VALUE;
  int minLon = Integer.MAX_VALUE;
  int maxLon = Integer.MIN_VALUE;
  
  for (int[] l : allLocations) { 
  
      int lat = (int) l[0];
      int lon = (int) l[1];
  
  
      maxLat = Math.max(lat, maxLat);
      minLat = Math.min(lat, minLat);
      maxLon = Math.max(lon, maxLon);
      minLon = Math.min(lon, minLon);
  
   }
  </code></pre>