title: Rss Reader giving Android Runtime Error
body: <p>I'm building a RSS/Atom feed reader which check different tag and takes in only the tags that we need.</p>
  
  <p>However, when I execute the code, I'm having an Android RunTime Exception.</p>
  
  <pre><code>04-29 23:56:20.745: D/ProgressBar(18432): setProgressDrawable mProgressDrawable = null, d = android.graphics.drawable.LayerDrawable@42347548needUpdate = false
  04-29 23:56:20.745: D/ProgressBar(18432): setProgressDrawable drawableHeight = 32
  04-29 23:56:20.745: D/ProgressBar(18432): setProgress = 0
  04-29 23:56:20.745: D/ProgressBar(18432): setProgress = 0, fromUser = false
  04-29 23:56:20.745: D/ProgressBar(18432): mProgress = 0mIndeterminate = false, mMin = 0, mMax = 100
  04-29 23:56:20.755: D/ProgressBar(18432): setProgress = 0
  04-29 23:56:20.755: D/ProgressBar(18432): setProgress = 0, fromUser = false
  04-29 23:56:20.755: D/ProgressBar(18432): mProgress = 0mIndeterminate = false, mMin = 0, mMax = 100
  04-29 23:56:20.865: D/libEGL(18432): loaded /vendor/lib/egl/libEGL_adreno.so
  04-29 23:56:20.875: D/libEGL(18432): loaded /vendor/lib/egl/libGLESv1_CM_adreno.so
  04-29 23:56:20.885: D/libEGL(18432): loaded /vendor/lib/egl/libGLESv2_adreno.so
  04-29 23:56:20.885: I/Adreno-EGL(18432): &lt;qeglDrvAPI_eglInitialize:316&gt;: EGL 1.4 QUALCOMM build: LNXBUILD_AU_LINUX_ANDROID_JB_3.2.4.04.03.00.173.012+PATCH[ES]_msm8226_JB_3.2.4__release_ENGG ()
  04-29 23:56:20.885: I/Adreno-EGL(18432): OpenGL ES Shader Compiler Version: 20.00.01
  04-29 23:56:20.885: I/Adreno-EGL(18432): Build Date: 02/27/14 Thu
  04-29 23:56:20.885: I/Adreno-EGL(18432): Local Branch: 
  04-29 23:56:20.885: I/Adreno-EGL(18432): Remote Branch: quic/jb_3.2.4
  04-29 23:56:20.885: I/Adreno-EGL(18432): Local Patches: 7de55685a2714b78da20f2a126b0dd72b0d2c0c4 Merge "PROFILER: fix default enabled/disabled setting"
  04-29 23:56:20.885: I/Adreno-EGL(18432):                  75d04ab84c7a68c72d92d59aae1827fcfef44b91 PROFILER: fix default enabled/disabled setting
  04-29 23:56:20.885: I/Adreno-EGL(18432): Reconstruct Branch: LOCAL_PATCH[ES]
  04-29 23:56:20.925: D/OpenGLRenderer(18432): Enabling debug mode 0
  04-29 23:56:20.925: D/ProgressBar(18432): updateDrawableBounds: left = 0
  04-29 23:56:20.925: D/ProgressBar(18432): updateDrawableBounds: top = 0
  04-29 23:56:20.925: D/ProgressBar(18432): updateDrawableBounds: right = 96
  04-29 23:56:20.925: D/ProgressBar(18432): updateDrawableBounds: bottom = 32
  04-29 23:56:20.925: D/ProgressBar(18432): updateDrawableBounds: mProgressDrawable.setBounds()
  04-29 23:56:21.885: D/ProgressBar(18432): setProgress = 1
  04-29 23:56:21.885: D/ProgressBar(18432): setProgress = 1, fromUser = false
  04-29 23:56:21.885: D/ProgressBar(18432): mProgress = 0mIndeterminate = false, mMin = 0, mMax = 100
  04-29 23:56:21.895: D/ProgressBar(18432): setProgress = 2
  04-29 23:56:21.895: D/ProgressBar(18432): setProgress = 2, fromUser = false
  04-29 23:56:21.895: D/ProgressBar(18432): mProgress = 1mIndeterminate = false, mMin = 0, mMax = 100
  04-29 23:56:21.895: D/ProgressBar(18432): setProgress = 3
  04-29 23:56:21.895: D/ProgressBar(18432): setProgress = 3, fromUser = false
  04-29 23:56:21.895: D/ProgressBar(18432): mProgress = 2mIndeterminate = false, mMin = 0, mMax = 100
  04-29 23:56:21.905: D/ProgressBar(18432): setProgress = 4
  04-29 23:56:21.905: D/ProgressBar(18432): setProgress = 4, fromUser = false
  04-29 23:56:21.905: D/ProgressBar(18432): mProgress = 3mIndeterminate = false, mMin = 0, mMax = 100
  04-29 23:56:21.945: D/ProgressBar(18432): setProgress = 5
  04-29 23:56:21.945: D/ProgressBar(18432): setProgress = 5, fromUser = false
  04-29 23:56:21.945: D/ProgressBar(18432): mProgress = 4mIndeterminate = false, mMin = 0, mMax = 100
  04-29 23:56:21.955: D/ProgressBar(18432): setProgress = 6
  04-29 23:56:21.955: D/ProgressBar(18432): setProgress = 6, fromUser = false
  04-29 23:56:21.955: D/ProgressBar(18432): mProgress = 5mIndeterminate = false, mMin = 0, mMax = 100
  04-29 23:56:21.955: D/ProgressBar(18432): setProgress = 7
  04-29 23:56:21.955: D/ProgressBar(18432): setProgress = 7, fromUser = false
  04-29 23:56:21.955: D/ProgressBar(18432): mProgress = 6mIndeterminate = false, mMin = 0, mMax = 100
  04-29 23:56:21.965: D/ProgressBar(18432): setProgress = 8
  04-29 23:56:21.965: D/ProgressBar(18432): setProgress = 8, fromUser = false
  04-29 23:56:21.965: D/ProgressBar(18432): mProgress = 7mIndeterminate = false, mMin = 0, mMax = 100
  04-29 23:56:21.975: D/ProgressBar(18432): setProgress = 9
  04-29 23:56:21.975: D/ProgressBar(18432): setProgress = 9, fromUser = false
  04-29 23:56:21.975: D/ProgressBar(18432): mProgress = 8mIndeterminate = false, mMin = 0, mMax = 100
  04-29 23:56:21.985: D/ProgressBar(18432): setProgress = 10
  04-29 23:56:21.985: D/ProgressBar(18432): setProgress = 10, fromUser = false
  04-29 23:56:21.985: D/ProgressBar(18432): mProgress = 9mIndeterminate = false, mMin = 0, mMax = 100
  04-29 23:56:21.985: D/ProgressBar(18432): setProgress = 11
  04-29 23:56:21.985: D/ProgressBar(18432): setProgress = 11, fromUser = false
  04-29 23:56:21.985: D/ProgressBar(18432): mProgress = 10mIndeterminate = false, mMin = 0, mMax = 100
  04-29 23:56:21.995: D/ProgressBar(18432): setProgress = 12
  04-29 23:56:21.995: D/ProgressBar(18432): setProgress = 12, fromUser = false
  04-29 23:56:21.995: D/ProgressBar(18432): mProgress = 11mIndeterminate = false, mMin = 0, mMax = 100
  04-29 23:56:22.015: D/ProgressBar(18432): setProgress = 13
  04-29 23:56:22.015: D/ProgressBar(18432): setProgress = 13, fromUser = false
  04-29 23:56:22.015: D/ProgressBar(18432): mProgress = 12mIndeterminate = false, mMin = 0, mMax = 100
  04-29 23:56:22.015: D/ProgressBar(18432): setProgress = 14
  04-29 23:56:22.015: D/ProgressBar(18432): setProgress = 14, fromUser = false
  04-29 23:56:22.015: D/ProgressBar(18432): mProgress = 13mIndeterminate = false, mMin = 0, mMax = 100
  04-29 23:56:22.025: D/ProgressBar(18432): setProgress = 15
  04-29 23:56:22.025: D/ProgressBar(18432): setProgress = 15, fromUser = false
  04-29 23:56:22.025: D/ProgressBar(18432): mProgress = 14mIndeterminate = false, mMin = 0, mMax = 100
  04-29 23:56:22.035: D/ProgressBar(18432): setProgress = 16
  04-29 23:56:22.035: D/ProgressBar(18432): setProgress = 16, fromUser = false
  04-29 23:56:22.035: D/ProgressBar(18432): mProgress = 15mIndeterminate = false, mMin = 0, mMax = 100
  04-29 23:56:22.045: D/ProgressBar(18432): setProgress = 17
  04-29 23:56:22.045: D/ProgressBar(18432): setProgress = 17, fromUser = false
  04-29 23:56:22.045: D/ProgressBar(18432): mProgress = 16mIndeterminate = false, mMin = 0, mMax = 100
  04-29 23:56:22.045: D/ProgressBar(18432): setProgress = 18
  04-29 23:56:22.045: D/ProgressBar(18432): setProgress = 18, fromUser = false
  04-29 23:56:22.045: D/ProgressBar(18432): mProgress = 17mIndeterminate = false, mMin = 0, mMax = 100
  04-29 23:56:22.065: D/ProgressBar(18432): setProgress = 19
  04-29 23:56:22.065: D/ProgressBar(18432): setProgress = 19, fromUser = false
  04-29 23:56:22.065: D/ProgressBar(18432): mProgress = 18mIndeterminate = false, mMin = 0, mMax = 100
  04-29 23:56:22.075: D/ProgressBar(18432): setProgress = 20
  04-29 23:56:22.075: D/ProgressBar(18432): setProgress = 20, fromUser = false
  04-29 23:56:22.075: D/ProgressBar(18432): mProgress = 19mIndeterminate = false, mMin = 0, mMax = 100
  04-29 23:56:22.075: D/ProgressBar(18432): setProgress = 21
  04-29 23:56:22.075: D/ProgressBar(18432): setProgress = 21, fromUser = false
  04-29 23:56:22.075: D/ProgressBar(18432): mProgress = 20mIndeterminate = false, mMin = 0, mMax = 100
  04-29 23:56:22.085: D/ProgressBar(18432): setProgress = 22
  04-29 23:56:22.085: D/ProgressBar(18432): setProgress = 22, fromUser = false
  04-29 23:56:22.085: D/ProgressBar(18432): mProgress = 21mIndeterminate = false, mMin = 0, mMax = 100
  04-29 23:56:22.095: D/ProgressBar(18432): setProgress = 23
  04-29 23:56:22.095: D/ProgressBar(18432): setProgress = 23, fromUser = false
  04-29 23:56:22.095: D/ProgressBar(18432): mProgress = 22mIndeterminate = false, mMin = 0, mMax = 100
  04-29 23:56:22.095: D/ProgressBar(18432): setProgress = 24
  04-29 23:56:22.095: D/ProgressBar(18432): setProgress = 24, fromUser = false
  04-29 23:56:22.095: D/ProgressBar(18432): mProgress = 23mIndeterminate = false, mMin = 0, mMax = 100
  04-29 23:56:22.105: D/ProgressBar(18432): setProgress = 25
  04-29 23:56:22.105: D/ProgressBar(18432): setProgress = 25, fromUser = false
  04-29 23:56:22.105: D/ProgressBar(18432): mProgress = 24mIndeterminate = false, mMin = 0, mMax = 100
  04-29 23:56:22.115: D/ProgressBar(18432): setProgress = 100
  04-29 23:56:22.115: D/ProgressBar(18432): setProgress = 100, fromUser = false
  04-29 23:56:22.115: D/ProgressBar(18432): mProgress = 25mIndeterminate = false, mMin = 0, mMax = 100
  04-29 23:56:22.115: D/AndroidRuntime(18432): Shutting down VM
  04-29 23:56:22.115: W/dalvikvm(18432): threadid=1: thread exiting with uncaught exception (group=0x41758898)
  04-29 23:56:22.125: E/AndroidRuntime(18432): FATAL EXCEPTION: main
  04-29 23:56:22.125: E/AndroidRuntime(18432): java.lang.NullPointerException
  04-29 23:56:22.125: E/AndroidRuntime(18432):    at com.itcuties.app.SplashActivity$GetRSSDataTask.onPostExecute(SplashActivity.java:81)
  04-29 23:56:22.125: E/AndroidRuntime(18432):    at com.itcuties.app.SplashActivity$GetRSSDataTask.onPostExecute(SplashActivity.java:1)
  04-29 23:56:22.125: E/AndroidRuntime(18432):    at android.os.AsyncTask.finish(AsyncTask.java:631)
  04-29 23:56:22.125: E/AndroidRuntime(18432):    at android.os.AsyncTask.access$600(AsyncTask.java:177)
  04-29 23:56:22.125: E/AndroidRuntime(18432):    at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:644)
  04-29 23:56:22.125: E/AndroidRuntime(18432):    at android.os.Handler.dispatchMessage(Handler.java:99)
  04-29 23:56:22.125: E/AndroidRuntime(18432):    at android.os.Looper.loop(Looper.java:176)
  04-29 23:56:22.125: E/AndroidRuntime(18432):    at android.app.ActivityThread.main(ActivityThread.java:5493)
  04-29 23:56:22.125: E/AndroidRuntime(18432):    at java.lang.reflect.Method.invokeNative(Native Method)
  04-29 23:56:22.125: E/AndroidRuntime(18432):    at java.lang.reflect.Method.invoke(Method.java:525)
  04-29 23:56:22.125: E/AndroidRuntime(18432):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1225)
  04-29 23:56:22.125: E/AndroidRuntime(18432):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1041)
  04-29 23:56:22.125: E/AndroidRuntime(18432):    at dalvik.system.NativeStart.main(Native Method)
  04-29 23:57:07.065: I/Process(18432): Sending signal. PID: 18432 SIG: 9
  </code></pre>
  
  <p>Here's my java File which does that,</p>
  
  <pre><code>package com.itcuties.app.util.atom;
  
  import java.text.ParseException;
  import java.util.ArrayList;
  import java.util.List;
  
  import org.xml.sax.Attributes;
  import org.xml.sax.SAXException;
  import org.xml.sax.helpers.DefaultHandler;
  
  import android.util.Log;
  import android.widget.ProgressBar;
  
  import com.itcuties.app.reader.data.RssAtomItem;
  import com.itcuties.app.util.text.TextConverter;
  
  
  public class RssAtomParseHandler extends DefaultHandler {
  
      private List&lt;RssAtomItem&gt; rssItems;
  
      // Used to reference item while parsing
      private RssAtomItem currentItem;
  
      // Parsing title indicator
      private boolean parsingTitle;
      // Parsing contents indicator
      private boolean parsingContents;
      // Parsing published date indicator
      private boolean parsingPublishedDate;
      // A buffer for title contents
      private StringBuffer currentTitleSb;
      // A buffer for content tag contents
      private StringBuffer currentContentSb;
      // A buffer for publish date tag contents;
      private StringBuffer currentPubishDateSb;
      // Parsing published Author name
      private boolean parsingAuthorName;
      // A buffer for Author Name
      private StringBuffer currentAuthorSb;
  
      // This is a ProgressBar reference set by the SplashScreen
      // We use it to show the real progress while each item from
      // the feed is read.
      private ProgressBar progressBar;
  
      public RssAtomParseHandler() {
          rssItems = new ArrayList&lt;RssAtomItem&gt;();
      }
  
      public List&lt;RssAtomItem&gt; getItems() {
          return rssItems;
      }
  
      public void setProgressBar(ProgressBar progressBar) {
          this.progressBar = progressBar;
      }
  
      @Override
      public void startElement(String uri, String localName, String qName,
              Attributes attributes) throws SAXException {
          if ("entry".equals(qName)) {
              currentItem = new RssAtomItem();
          } else if ("title".equals(qName)) {
              parsingTitle = true;
              currentTitleSb = new StringBuffer();
          } else if ("author".equals(qName)) {
              parsingAuthorName = true;
              currentAuthorSb = new StringBuffer();
          } else if ("content".equals(qName)) {
              parsingContents = true;
              currentContentSb = new StringBuffer();
          } else if ("published".equals(qName)) {
              parsingPublishedDate = true;
              currentPubishDateSb = new StringBuffer();
          } else if ("category".equals(qName)) {
              if (currentItem != null &amp;&amp; currentItem.getCategory() == null) {
                  currentItem.setCategory(attributes.getValue("term"));
              }
          }
      }
  
      @Override
      public void endElement(String uri, String localName, String qName)
              throws SAXException {
          if ("entry".equals(qName)) {
              rssItems.add(currentItem);
              currentItem = null;
          } else if ("title".equals(qName)) {
              parsingTitle = false;
  
              // There is a title tag for a whole channel present.
              // It is being parsed before the entry tag is present,
              // so we need to check if item is not null
              if (currentItem != null)
                  // We encode the title so that it can be read by the application
                  // properly
                  currentItem.setTitle(TextConverter.convertTitle(currentTitleSb
                          .toString()));
  
          } else if ("content".equals(qName)) {
              parsingContents = false;
  
              if (currentItem != null) {
                  // When an item's content is being set we convert it a little
                  // bit:
                  // - All styles and JavaScript information are removed
                  // - Content is URL encoded so that the WebView component can
                  // display it correctly
                  // - We remove two sections which are added by the ATOM feed,
                  // the post info section
                  // and the code download section (only github link is present in
                  // the text)
                  currentItem.setContent(TextConverter
                          .clearStylesAndJS(TextConverter.URLEncode(TextConverter
                                  .removePostInfoSection(TextConverter
                                          .removeDownloadSection(currentContentSb
                                                  .toString())))));
  
                  // Update progressBar
                  progressBar.setProgress(progressBar.getProgress() + 1);
  
              } else if ("author".equals(qName)) {
                  parsingAuthorName = false;
  
                  if (currentItem != null) {
  
                      currentItem.setAuthor(currentAuthorSb.toString());
  
                      // Update progressBar
                      progressBar.setProgress(progressBar.getProgress() + 1);
  
                  }
  
              } else if ("published".equals(qName)) {
                  parsingPublishedDate = false;
  
                  if (currentItem != null)
                      try {
                          // We convert the date from the WordPress format to
                          // DD-MM-YYYY format
                          currentItem.setPublishDate(TextConverter
                                  .convertDate(currentPubishDateSb.toString()));
                      } catch (ParseException e) {
                          currentItem.setPublishDate("no date");
                          Log.e("ITCRssReader", "No publish date available");
                      }
  
              }
  
          }
      }
  
      @Override
      public void characters(char[] ch, int start, int length)
              throws SAXException {
          // title, contents and date tags contents values are set here.
          // This method can be called multiple times for one tag, it depends
          // on how much text tag's contents has. Remember that SAX is a
          // stream parser so it parses feed stream sequentially.
          if (parsingTitle) {
              if (currentItem != null)
                  currentTitleSb.append(new String(ch, start, length));
          } else if (parsingAuthorName) {
              if (currentItem != null)
                  currentAuthorSb.append(new String(ch, start, length));
  
              else if (parsingContents) {
                  if (currentItem != null)
                      currentContentSb.append(new String(ch, start, length));
              } else if (parsingPublishedDate) {
                  if (currentItem != null)
                      currentPubishDateSb.append(new String(ch, start, length));
              }
          }
  
      }
  }
  </code></pre>
  
  <p>Here's the Splash Activity that uses AsyncTask.</p>
  
  <pre><code>package com.itcuties.app;
  
  import java.util.List;
  
  import android.app.Activity;
  import android.content.Intent;
  import android.os.AsyncTask;
  import android.os.Bundle;
  import android.util.Log;
  import android.widget.ProgressBar;
  import android.widget.Toast;
  
  import com.itcuties.app.reader.data.RssAtomItem;
  import com.itcuties.app.reader.data.RssResults;
  import com.itcuties.app.util.atom.RssAtomReader;
  
  /**
   * Application splash screen. It also loads data.
   * 
  
   */
  public class SplashActivity extends Activity {
  
      private ProgressBar progressBar;
      private Toast t;
      String done ="Done!";
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
  
          setContentView(R.layout.splash);
  
          progressBar = (ProgressBar)findViewById(R.id.progressBar);
          progressBar.setProgress(0); // No progress so far
  
          // Download data in the new thread
          GetRSSDataTask grdt = new GetRSSDataTask();
          grdt.execute("[Feed Address goes here]");
  
      }
  
      /**
       * Read RSS channel data.
       * 
       *
       */
      private class GetRSSDataTask extends AsyncTask&lt;String, Void, List&lt;RssAtomItem&gt; &gt; {
          @Override
          protected List&lt;RssAtomItem&gt; doInBackground(String... urls) {
              try {
                  // Create RSS reader
                  RssAtomReader rssReader = new RssAtomReader(urls[0]);
                  rssReader.setProgressBar(progressBar); // Set the progress bar to show real progress
  
                  // Parse RSS, get items
                  return rssReader.getItems();
  
              } catch (Exception e) {
                  Log.e("BlanketCoffeeRSS", e.getMessage());
              }
  
              return null;
          }
  
          @Override
          protected void onPostExecute(List&lt;RssAtomItem&gt; results) {
              // When the download is done the main activity needs to be started
              Intent i = new Intent(SplashActivity.this, ListPostsActivity.class);
  
              // You might find this not right to use a static attribute to pass data between the 
              // the activities in the application. We tried to pass the List of the RssAtomItem 
              // object with no luck although RssAtomItem implemented Serializable interface.
              // ListPostActivity read null values. So this is the engineer's solution. It works :)
              RssResults.setResults(results); //We need to set the results of the download process
  
              // Show 100% progress
              progressBar.setProgress(100);
              t.setText(done);
              t.show();
  
              // Start new activity and finish this splash activity
              SplashActivity.this.startActivity(i);
              SplashActivity.this.finish();
  
          }
  
      }
  
  }
  </code></pre>
  
  <p>Can Anybody tell me where am I doing it wrong? The number of author tags are 50, as supposed to the 15 odd posts. Is that creating a problem or something else?</p>