title: Why is this method not sorting the XML parser?
body: <p>I would like to sort my list by Clinic name, the parser works fortunately. However the sorting technique I have used does not. Have I implemented it incorrectly?</p>
  
  <pre><code>    public class BookScreen extends Activity {
  
          //array
          ArrayList&lt;HashMap&lt;String, String&gt;&gt; songsList;
          ProgressDialog mProgressDialog;
          // All static variables
          static final String URL = "https://dl.dropboxusercontent.com/u/42241589/test.xml";
          // XML node keys
          static final String KEY_CLINIC = "clinic"; // parent node
          static final String KEY_ID = "id";
          static final String KEY_TITLE = "title";
          static final String KEY_DATE = "date";
          static final String KEY_TIME = "time";
          static final String KEY_ADDRESS = "address";
          //static final String KEY_THUMB_URL = "thumbnail";
          ListView list;
          LazyAdapter adapter;
  
          @SuppressLint("NewApi")
          @Override
          public void onCreate(Bundle savedInstanceState) {
              super.onCreate(savedInstanceState);
              setContentView(R.layout.book_main);
              new DownloadXML().execute();
          }
  
          private class DownloadXML extends AsyncTask&lt;Void, Void, Void&gt; {
  
              protected void onPreExecute() {
                  super.onPreExecute();
                  mProgressDialog = new ProgressDialog(BookScreen.this);
                  mProgressDialog.setTitle("List is loading");
                  mProgressDialog.setMessage("Loading...");
                  mProgressDialog.setIndeterminate(false);
                  mProgressDialog.show();
              }
  
              protected Void doInBackground(Void... params) {
                  songsList = new ArrayList&lt;HashMap&lt;String, String&gt;&gt;();
                  XMLParser parser = new XMLParser();
                  String xml = parser.getXmlFromUrl(URL); // getting XML from URL
                  Document doc = parser.getDomElement(xml); // getting DOM element
                  try {
                      NodeList nl = doc.getElementsByTagName(KEY_CLINIC); //define parent node
                      // looping through all song nodes &amp;lt;song&amp;gt;
                      for (int i = 0; i &lt; nl.getLength(); i++) {
                          // creating new HashMap
                          HashMap&lt;String, String&gt; map = new HashMap&lt;String, String&gt;();
                          Element e = (Element) nl.item(i);
                          // adding each child node to HashMap key =&amp;gt; value
                          map.put(KEY_ID, parser.getValue(e, KEY_ID));
                          map.put(KEY_TITLE, parser.getValue(e, KEY_TITLE));
                          map.put(KEY_DATE, parser.getValue(e, KEY_DATE));
                          map.put(KEY_TIME, parser.getValue(e, KEY_TIME));
                          map.put(KEY_ADDRESS, parser.getValue(e, KEY_ADDRESS));
                          //map.put(KEY_THUMB_URL, parser.getValue(e, KEY_THUMB_URL));
                          // adding HashList to ArrayList
                          songsList.add(map);
                      }
                  } catch (Exception e) {
                      Log.e("Error", e.getMessage());
                      e.printStackTrace();
                  }
                  return null;
              }
  
              protected void onPostExecute(Void args) {
                      list=(ListView)findViewById(R.id.list);
                  // Getting adapter by passing xml data ArrayList
                  Collections.sort(songsList, comparator);
                  adapter = new LazyAdapter(BookScreen.this, songsList);
                  adapter.notifyDataSetChanged();
                  list.setAdapter(adapter);
                  //Close dialog
                  mProgressDialog.dismiss();
              }
          }
          Comparator&lt;HashMap&lt;String, String&gt;&gt; comparator = new Comparator&lt;HashMap&lt;String, String&gt;&gt;() {
                  @Override
                  public int compare(HashMap&lt;String, String&gt; map1, HashMap&lt;String, String&gt; map2) {
                      return map1.get(KEY_CLINIC).compareTo(map2.get(KEY_CLINIC));
                  }
  
  
      };
  }
  </code></pre>
  
  <p>The logcat points to an NullPointerException at `return   map1.get(KEY_CLINIC).compareTo(map2.get(KEY_CLINIC));' in the <strong>method comparator</strong>.</p>
  
  <pre><code>12-01 11:25:34.730: E/AndroidRuntime(885): FATAL EXCEPTION: main
  12-01 11:25:34.730: E/AndroidRuntime(885): Process: com.example.clinicbooker, PID: 885
  12-01 11:25:34.730: E/AndroidRuntime(885): java.lang.NullPointerException
  12-01 11:25:34.730: E/AndroidRuntime(885):  at com.example.clinicbooker.BookScreen$1.compare(BookScreen.java:102)
  12-01 11:25:34.730: E/AndroidRuntime(885):  at com.example.clinicbooker.BookScreen$1.compare(BookScreen.java:1)
  12-01 11:25:34.730: E/AndroidRuntime(885):  at java.util.TimSort.countRunAndMakeAscending(TimSort.java:320)
  12-01 11:25:34.730: E/AndroidRuntime(885):  at java.util.TimSort.sort(TimSort.java:185)
  12-01 11:25:34.730: E/AndroidRuntime(885):  at java.util.TimSort.sort(TimSort.java:169)
  12-01 11:25:34.730: E/AndroidRuntime(885):  at java.util.Arrays.sort(Arrays.java:2023)
  12-01 11:25:34.730: E/AndroidRuntime(885):  at java.util.Collections.sort(Collections.java:1883)
  12-01 11:25:34.730: E/AndroidRuntime(885):  at com.example.clinicbooker.BookScreen$DownloadXML.onPostExecute(BookScreen.java:91)
  12-01 11:25:34.730: E/AndroidRuntime(885):  at com.example.clinicbooker.BookScreen$DownloadXML.onPostExecute(BookScreen.java:1)
  12-01 11:25:34.730: E/AndroidRuntime(885):  at android.os.AsyncTask.finish(AsyncTask.java:632)
  12-01 11:25:34.730: E/AndroidRuntime(885):  at android.os.AsyncTask.access$600(AsyncTask.java:177)
  12-01 11:25:34.730: E/AndroidRuntime(885):  at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:645)
  12-01 11:25:34.730: E/AndroidRuntime(885):  at android.os.Handler.dispatchMessage(Handler.java:102)
  12-01 11:25:34.730: E/AndroidRuntime(885):  at android.os.Looper.loop(Looper.java:137)
  12-01 11:25:34.730: E/AndroidRuntime(885):  at android.app.ActivityThread.main(ActivityThread.java:4998)
  12-01 11:25:34.730: E/AndroidRuntime(885):  at java.lang.reflect.Method.invokeNative(Native Method)
  12-01 11:25:34.730: E/AndroidRuntime(885):  at java.lang.reflect.Method.invoke(Method.java:515)
  12-01 11:25:34.730: E/AndroidRuntime(885):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:777)
  12-01 11:25:34.730: E/AndroidRuntime(885):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:593)
  12-01 11:25:34.730: E/AndroidRuntime(885):  at dalvik.system.NativeStart.main(Native Method)
  </code></pre>