title: ExpatParser$ParseException when parsing a local xml file using SAX parser in android
body: <p>I'm trying to learn how to parse an xml file using SAX parser in Android.</p>
  
  <p>I placed an example xml file as such: res/xml/example.xml
  Here is the xml code</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;maintag&gt;
      &lt;item&gt;
          &lt;name&gt;
              AndroidPeople
          &lt;/name&gt;
  
          &lt;website category="android" &gt;
              www.androidpeople.com
          &lt;/website&gt;
      &lt;/item&gt;
  
      &lt;item&gt;
          &lt;name&gt;
              iPhoneAppDeveloper
          &lt;/name&gt;
  
          &lt;website category="iPhone" &gt;
              www.iphone-app-developer.com
          &lt;/website&gt;
      &lt;/item&gt;
  &lt;/maintag&gt;
  </code></pre>
  
  <p>Here is the main Activity class</p>
  
  <pre><code>package com.me.xml_trail;
  
  import javax.xml.parsers.SAXParser;
  import javax.xml.parsers.SAXParserFactory;
  
  import org.xml.sax.InputSource;
  import org.xml.sax.XMLReader;
  
  import android.app.Activity;
  import android.os.Bundle;
  import android.util.Log;
  import android.widget.LinearLayout;
  import android.widget.TextView;
  
  public class XMLParsingExample extends Activity
  {
      /** Create Object For SiteList Class */
      SitesList sitesList = null;
  
      SAXParserFactory spf;
      SAXParser sp;
      XMLReader xr;
      InputSource is;
      MyXMLHandler myXMLHandler;
  
      /** Called when the activity is first created. */
      @Override
      public void onCreate(Bundle savedInstanceState)
      {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.main_layout);
  
          /** Create a new layout to display the view */
          LinearLayout layout = new LinearLayout(this);
          layout.setOrientation(1);
  
          /** Create a new textview array to display the results */
          TextView name[];
          TextView website[];
          TextView category[];
  
          try
          {
              /** Handling XML */
              spf = SAXParserFactory.newInstance();
          }
          catch (Exception e)
          {
              Log.d("mytag","1 " + e);
          }
  
          try
          {
              sp = spf.newSAXParser();
          }
          catch (Exception e)
          {
              Log.d("mytag","2 " + e);
          }
  
          try
          {
              xr = sp.getXMLReader();
          }
          catch (Exception e)
          {
              Log.d("mytag","3 " + e);
          }
  
          try
          {           
              /** Send URL to parse XML Tags */
              is = new InputSource(getResources().openRawResource(R.xml.example));
              is.setEncoding("utf-8");
          }
          catch (Exception e)
          {
              Log.d("mytag","4 " + e);
          }
  
          try
          {
              /** Create handler to handle XML Tags ( extends DefaultHandler ) */
              myXMLHandler = new MyXMLHandler();
          }
          catch (Exception e)
          {
              Log.d("mytag","5 " + e);
          }
  
          try
          {
              xr.setContentHandler(myXMLHandler);
          }
          catch (Exception e)
          {
              Log.d("mytag","6 " + e);
          }
  
          try
          {
              xr.parse(new InputSource(is.getByteStream()));      
          }
          catch (Exception e)
          {
              Log.d("mytag","7 " + e);
          }
  
          /** Get result from MyXMLHandler SitlesList Object */
          sitesList = MyXMLHandler.sitesList;
  
          /** Assign textview array lenght by arraylist size */
          name = new TextView[sitesList.getName().size()];
          website = new TextView[sitesList.getName().size()];
          category = new TextView[sitesList.getName().size()];
  
          /** Set the result text in textview and add it to layout */
          for (int i = 0; i &lt; sitesList.getName().size(); i++)
          {
              name[i] = new TextView(this);
              name[i].setText("Name = " + sitesList.getName().get(i));
              website[i] = new TextView(this);
              website[i].setText("Website = " + sitesList.getWebsite().get(i));
              category[i] = new TextView(this);
              category[i].setText("Website Category = " + sitesList.getCategory().get(i));
  
              layout.addView(name[i]);
              layout.addView(website[i]);
              layout.addView(category[i]);
          }
  
          /** Set the layout view to display */
          setContentView(layout);
      }
  }
  </code></pre>
  
  <p>Here is my logcat</p>
  
  <pre><code>cscCountry is not German : BTU
  
   7 org.apache.harmony.xml.ExpatParser$ParseException: At line 1, column 0: not well-formed (invalid token)
  
   threadid=1: thread exiting with uncaught exception (group=0x40018578)
  
   FATAL EXCEPTION: main
  
   java.lang.RuntimeException: Unable to start activity ComponentInfo{com.me.xml_trail/com.me.xml_trail.XMLParsingExample}: java.lang.NullPointerException
  
   at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1651)
  
   at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
  
   at android.app.ActivityThread.access$1500(ActivityThread.java:117)
  
   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
  
   at android.os.Handler.dispatchMessage(Handler.java:99)
  
   at android.os.Looper.loop(Looper.java:130)
  
   at android.app.ActivityThread.main(ActivityThread.java:3687)
  
   at java.lang.reflect.Method.invokeNative(Native Method)
  
   at java.lang.reflect.Method.invoke(Method.java:507)
  
   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
  
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
  
   at dalvik.system.NativeStart.main(Native Method)
  
   Caused by: java.lang.NullPointerException
  
   at com.me.xml_trail.XMLParsingExample.onCreate(XMLParsingExample.java:113)
  
   at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
  
   at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1615)
  
   ... 11 more
  </code></pre>
  
  <p>The problem is in the line xr.parse(new InputSource(is.getByteStream()));
  Why do I get this </p>