title: NullPointerException in onCreate(), but not in onLocationChanged()
body: <p>I am developing an android app and find something weird about NullPointerException. 
  The same method retrieveCampusFromXml() can run in onLocationChanged() but it throws NPE in onCreate(). Does someone know why?</p>
  
  <p>If I put it in onCreate() :</p>
  
  <pre><code>public class XXXX extends Activity {
      XmlResourceParser xrpCampus;
      ArrayList&lt;Destination&gt; campusDestinations = new ArrayList&lt;Destination&gt; ();
      firstRunForXML = true;
  @Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      appState = ((MyApp)this.getApplication());
      mContext = this;
      xrpCampus = getResources().getXml(R.xml.campus);
      campusDestinations = retrieveCampusFromXml(xrpCampus);campusDestinations = retrieveCampusFromXml(xrpCampus);
      mLocationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
  
      Criteria criteria = new Criteria();
      criteria.setAccuracy(Criteria.NO_REQUIREMENT);
      criteria.setPowerRequirement(Criteria.NO_REQUIREMENT);
  
      best = mLocationManager.getBestProvider(criteria, true);
  
      mLocationManager.requestLocationUpdates(best, 1000, 0, mLocationListener);
  </code></pre>
  
  <p>retrieveCampusFromXml() (which included lots of custom object, e.g. Destination):</p>
  
  <pre><code>private ArrayList&lt;Destination&gt; retrieveCampusFromXml(XmlResourceParser xrp) {
      ArrayList&lt;Destination&gt; listOfCampus = new ArrayList&lt;Destination&gt; ();
  
      String tagName = "";
      try {
          Destination temp=null;
          int latXml=0;
          int lngXml=0;
          int eventType = xrp.getEventType();
          while (eventType != XmlPullParser.END_DOCUMENT) {
              if (eventType == XmlPullParser.START_TAG) {
                  tagName = xrp.getName();
                  if(tagName.equals("destination")) {
                      temp = new Destination();
                  }
              }
              else if (eventType == XmlPullParser.END_TAG) {
                  tagName="";
  
                  if(xrp.getName().equals("destination")) {
                      temp.setGeoPoint(latXml, lngXml);
                      listOfCampus.add(temp);
                      latXml=0;
                      lngXml=0;
                  }
              }
              else if (eventType == XmlPullParser.TEXT) {
                  if (tagName.equals("name")) {
                      temp.setName(xrp.getText());
                  }
                  else if (tagName.equals("latitude")) {
                      latXml = (int) (Double.parseDouble(xrp.getText())*1E6);
                  }
                  else if (tagName.equals("longitude")) {
                      lngXml = (int) (Double.parseDouble(xrp.getText())*1E6);
                  }
                  else if (tagName.equals("altitude") &amp;&amp; !xrp.getText().equals("undefined")) {
                      temp.setAltitude(Double.parseDouble(xrp.getText()) );
                  }
                  else if (tagName.equals("drawableID") ) {
                      temp.setDrawable( mContext, Integer.decode(xrp.getText()) );
                  }
              }
              eventType = xrp.next();
          }
  
      } catch (XmlPullParserException e) {
          Log.i("LUN", "XML");
          e.printStackTrace();
      } catch (IOException e) {
          Log.i("LUN", "IO");
          e.printStackTrace();
      } catch (NullPointerException e) {
          Log.i("LUN", "NULL");
          e.printStackTrace();
      }
      return listOfCampus;
  }
  </code></pre>
  
  <p>If I put it in onLocationChanged() like that, everything's ok: </p>
  
  <pre><code>final LocationListener mLocationListener = new LocationListener() {
      public void onLocationChanged(Location arg0) {
          myLocation = arg0;
          if (myLocation != null) {
              if (firstRunForXML) {
                  firstRunForXML = false;
                  campusDestinations = retrieveCampusFromXml(xrpCampus);
              }
         }
  }
  </code></pre>
  
  <p>And I am new to Android, is the stacktrace like that I should provide? : </p>
  
  <pre><code>Thread [&lt;3&gt; main] (Suspended (exception NullPointerException))  
  ViewRoot.draw(boolean) line: 1373   
  ViewRoot.performTraversals() line: 1114 
  ViewRoot.handleMessage(Message) line: 1633  
  ViewRoot(Handler).dispatchMessage(Message) line: 99 
  Looper.loop() line: 123 
  ActivityThread.main(String[]) line: 4363    
  Method.invokeNative(Object, Object[], Class, Class[], Class, int, boolean) line: not available [native method]  
  Method.invoke(Object, Object...) line: 521  
  ZygoteInit$MethodAndArgsCaller.run() line: 860  
  ZygoteInit.main(String[]) line: 618 
  NativeStart.main(String[]) line: not available [native method]  
  </code></pre>