title: Returning empty List cause NullPointerException
body: <p><br>
  I was trying to make a simple feed XML reader and I've followed <a href="https://developer.android.com/training/basics/network-ops/xml.html" rel="nofollow">Parsing XML Data</a> from <code>Android Developers</code> site.<br>
  I get an error when converting a <code>List</code> to an <code>Array</code>: </p>
  
  <pre><code>java.lang.NullPointerException: Attempt to invoke interface method 'int java.util.List.size()' on a null object reference
  </code></pre>
  
  <p>The <code>List</code> is implemented in the <code>ParseXML.java</code> class and I don't know where it's wrong.<br>
  I leave my code below, thanks to all!</p>
  
  <p><code>NewsFeedFragment.java</code></p>
  
  <pre><code>public void downloadWebpage(String link) {
  
      if (checkInternetConnection()) {
          // CALL AND GET LIST
          new DownloadFile(this).execute(link);
      }
      else {
          Toast.makeText(getActivity(), "Disconnected!", Toast.LENGTH_SHORT).show();
      }
  }
  
  public boolean checkInternetConnection() {
      ConnectivityManager connectivityManager =
              (ConnectivityManager) getContext().getSystemService(Context.CONNECTIVITY_SERVICE);
      NetworkInfo activeNetwork = connectivityManager.getActiveNetworkInfo();
  
      return activeNetwork != null &amp;&amp; activeNetwork.isConnectedOrConnecting();
  }
  
  @Override
  public void onTaskCompleted(List&lt;PostData&gt; data) {
      PostData[] array = data.toArray(new PostData[data.size()]);
      PostItemAdapter adapter = new PostItemAdapter(getActivity(), R.layout.postitem, array);
      ListView listView = (ListView) getActivity().findViewById(R.id.news_feed_listView);
      listView.setAdapter(adapter);
  }
  </code></pre>
  
  <p><code>DownloadFile.java</code></p>
  
  <pre><code>private OnTaskCompleted listener;
  
  public DownloadFile(OnTaskCompleted listener) {
      this.listener = listener;
  }
  
  @Override
  protected List doInBackground(String... urls) {
      try {
          return loadXmlFromNetwork(urls[0]);
      } catch (IOException e) {
          e.printStackTrace();
      } catch (XmlPullParserException e) {
          e.printStackTrace();
      }
  
      return null;
  }
  
  @Override
  protected void onPostExecute(List result) {
      listener.onTaskCompleted(result);
  }
  
  
  private List loadXmlFromNetwork(String link) throws XmlPullParserException, IOException {
      List&lt;PostData&gt; postData = null;
      InputStream inputStream = null;
      ParseXML parseXML = new ParseXML();
      //String stringHtml = null;
  
      try {
          inputStream = downloadUrl(link);
          //stringHtml = convertToString(inputStream);              
          postData = parseXML.parse(inputStream);
      } finally {
          if (inputStream != null) {
              inputStream.close();
          }
      }
  
      return postData;
  }
  
  private InputStream downloadUrl(String urlString) throws IOException {
      URL url = new URL(urlString);
      HttpURLConnection conn = (HttpURLConnection) url.openConnection();
      conn.setReadTimeout(10000);
      conn.setConnectTimeout(15000);
      conn.setRequestMethod("GET");
      conn.setDoInput(true);
  
      conn.connect();
      return conn.getInputStream();
  }
  </code></pre>
  
  <p><code>ParseXML.java</code></p>
  
  <pre><code>public class ParseXML extends DefaultHandler {
  
  private static final String ns = null;
  
  // Requires InputStream and create a XmlPullParser with a IS input
  public List parse(InputStream in) throws XmlPullParserException, IOException {
      try {
          XmlPullParser parser = Xml.newPullParser();
          parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, false);
          parser.setInput(in, null);
          parser.nextTag();
          return readFeed(parser);
      } finally {
          in.close();
      }
  }
  
  private List readFeed(XmlPullParser parser) throws XmlPullParserException, IOException {
      List entries = new ArrayList();
  
      parser.require(XmlPullParser.START_TAG, ns, "channel");
      while (parser.next() != XmlPullParser.END_TAG) {
          if (parser.getEventType() != XmlPullParser.START_TAG) {
              continue;
          }
          String name = parser.getName();
          if (name.equals("item")) {
              entries.add(readItem(parser));
          }
          else{
              skip(parser);
          }
      }
      return entries;
  }
  
  private PostData readItem(XmlPullParser parser) throws XmlPullParserException, IOException {
      parser.require(XmlPullParser.START_TAG, ns, "entry");
      String title = null;
      String description = null;
      String link = null;
  
      while (parser.next() != XmlPullParser.END_TAG) {
          if (parser.getEventType() != XmlPullParser.START_TAG) {
              continue;
          }
          String name = parser.getName();
          if (name.equals("title")) {
              title = readTitle(parser);
          }
          else if (name.equals("link")) {
              link = readLink(parser);
          }
          else if (name.equals("description")) {
              description = readDescription(parser);
          }
      }
      return new PostData(title, link, description);
  }
  
  private String readTitle(XmlPullParser parser) throws XmlPullParserException, IOException {
      parser.require(XmlPullParser.START_TAG, ns, "title");
      String title = readText(parser);
      parser.require(XmlPullParser.END_TAG, ns, "title");
      return title;
  }
  
  private String readLink(XmlPullParser parser) throws XmlPullParserException, IOException {
      parser.require(XmlPullParser.START_TAG, ns, "link");
      String link = readText(parser);
      parser.require(XmlPullParser.END_TAG, ns, "link");
      return link;
  }
  
  private String readDescription(XmlPullParser parser) throws XmlPullParserException, IOException {
      parser.require(XmlPullParser.START_TAG, ns, "description");
      String description = readText(parser);
      parser.require(XmlPullParser.END_TAG, ns, "description");
      return description;
  }
  
  private String readText(XmlPullParser parser) throws XmlPullParserException, IOException {
      String result = "";
      if (parser.next() == XmlPullParser.TEXT) {
          result = parser.getText();
          parser.nextTag();
      }
      return result;
  }
  
  private void skip(XmlPullParser parser) throws XmlPullParserException, IOException {
      if (parser.getEventType() != XmlPullParser.START_TAG) {
          throw new IllegalStateException();
      }
      int depth = 1;
      while (depth != 0) {
          switch (parser.next()) {
              case XmlPullParser.END_TAG:
                  depth--;
                  break;
              case XmlPullParser.START_TAG:
                  depth++;
                  break;
          }
      }
  }
  }
  </code></pre>