title: Parsing an XML file in the sdcard - comes up with null pointer exception
body: <p>All I want is to parse a local XML file. The code works correctly when I place the XML file in my resource folder. Here's my code.</p>
  
  <pre><code>try {
  
          XmlResourceParser xpp = getResources().getXml(R.xml.catalog);
          xpp.next();
          int eventType = xpp.getEventType();
          int iter = 0;
          String elemtext = null;
  
          while (eventType != XmlPullParser.END_DOCUMENT) {
  
              if (eventType == XmlPullParser.START_TAG) {
  
                  String elemName = xpp.getName();
                  if (elemName.equals("catalog")) {
                      String journalAttr = xpp.getAttributeValue(null,
                              "journal");
                      String publisherAttr = xpp.getAttributeValue(null,
                              "publisher");
                      journal.setText(journalAttr);
                      publisher.setText(publisherAttr);
                  }
                  if (elemName.equals("article")) {
                      iter = iter + 1;
                  }
  
                  if (elemName.equals("edition")) {
                      elemtext = "edition";
                  }
                  if (elemName.equals("title")) {
                      elemtext = "title";
                  }
                  if (elemName.equals("author")) {
                      elemtext = "author";
                  }
              }
  
              else if (eventType == XmlPullParser.TEXT) {
                  if (iter == 1) {
                      if (elemtext.equals("edition")) {
                          edition1.setText(xpp.getText());
                      } else if (elemtext.equals("title")) {
                          title1.setText(xpp.getText());
                      } else if (elemtext.equals("author")) {
                          author1.setText(xpp.getText());
                      }
                  }
  
                  else if (iter == 2) {
                      if (elemtext.equals("edition")) {
                          edition2.setText(xpp.getText());
                      } else if (elemtext.equals("title")) {
                          title2.setText(xpp.getText());
                      } else if (elemtext.equals("author")) {
                          author2.setText(xpp.getText());
                      }
  
                  }
              }
              eventType = xpp.next();
          }
  
      } catch (XmlPullParserException e) {
      } catch (IOException e) {
      }
  </code></pre>
  
  <p>now my intention is to get the code working if the same file is placed in the sdcard.
  here's my efforts.</p>
  
  <pre><code>try {
  
          XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
          factory.setNamespaceAware(true);
          XmlPullParser xpp = factory.newPullParser();
          int eventType = xpp.getEventType();
          int iter = 0;
          String elemtext = null;
          // get a reference to the file.
          File file = new File(Environment.getExternalStorageDirectory()
                  + "/newdir/catalog.xml");
          FileInputStream fis = new FileInputStream(file);
  
          xpp.setInput(new InputStreamReader(fis));
  
          while (eventType != XmlPullParser.END_DOCUMENT) {
  
              if (eventType == XmlPullParser.START_TAG) {
  
                  String elemName = xpp.getName();
                  if (elemName.equals("catalog")) {
                      String journalAttr = xpp.getAttributeValue(null,
                              "journal");
                      String publisherAttr = xpp.getAttributeValue(null,
                              "publisher");
                      journal.setText(journalAttr);
                      publisher.setText(publisherAttr);
                  }
                  if (elemName.equals("article")) {
                      iter = iter + 1;
                  }
  
                  if (elemName.equals("edition")) {
                      elemtext = "edition";
                  }
                  if (elemName.equals("title")) {
                      elemtext = "title";
                  }
                  if (elemName.equals("author")) {
                      elemtext = "author";
                  }
              }
  
              else if (eventType == XmlPullParser.TEXT) {
                  if (iter == 1) {
                      if (elemtext.equals("edition")) {
                          edition1.setText(xpp.getText());
                      } else if (elemtext.equals("title")) {
                          title1.setText(xpp.getText());
                      } else if (elemtext.equals("author")) {
                          author1.setText(xpp.getText());
                      }
                  }
  
                  else if (iter == 2) {
                      if (elemtext.equals("edition")) {
                          edition2.setText(xpp.getText());
                      } else if (elemtext.equals("title")) {
                          title2.setText(xpp.getText());
                      } else if (elemtext.equals("author")) {
                          author2.setText(xpp.getText());
                      }
  
                  }
              }
              eventType = xpp.next();
          }
  
      } catch (XmlPullParserException e) {
      } catch (IOException e) {
      }
  </code></pre>
  
  <p>I get null pointer exception when i use this code. Help me sort this out.</p>