title: Null point error while parsing xml file
body: <p>I tried an example of parsing and showing data from xml file and hence i followed <a href="http://www.androidpeople.com/android-xml-parsing-tutorial-%E2%80%93-using-domparser" rel="nofollow noreferrer">parsexml</a> tutorial. I replaced this xml file with my own xml file which i stored on my server.My xml file is valid one and i checked this by loading it on my chrome.My problem is while running my project it is throwing an error as null point error and when i debug my app near xml file it is giving an error of page not found. With this i attached my logcat. Can anyone tell me why am getting this error . I referred <a href="https://stackoverflow.com/questions/13180606/parsing-xml-android-description-tag-parsing">this</a> but no use. My logcat is </p>
  
  <pre><code>12-26 02:34:20.230: E/Error:(1734): expected: /META read: HEAD (position:END_TAG &lt;/HEAD&gt;@11:8 in java.io.StringReader@41829778) 
  12-26 02:34:20.230: D/AndroidRuntime(1734): Shutting down VM
  12-26 02:34:20.230: W/dalvikvm(1734): threadid=1: thread exiting with uncaught exception (group=0x414c4700)
  12-26 02:34:20.240: E/AndroidRuntime(1734): FATAL EXCEPTION: main
  12-26 02:34:20.240: E/AndroidRuntime(1734): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.testing.mypractise/com.practise.loadimagefromxml.AndroidXMLParsingActivity}: java.lang.NullPointerException
  12-26 02:34:20.240: E/AndroidRuntime(1734):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2211)
  12-26 02:34:20.240: E/AndroidRuntime(1734):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
  12-26 02:34:20.240: E/AndroidRuntime(1734):     at android.app.ActivityThread.access$600(ActivityThread.java:141)
  12-26 02:34:20.240: E/AndroidRuntime(1734):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
  12-26 02:34:20.240: E/AndroidRuntime(1734):     at android.os.Handler.dispatchMessage(Handler.java:99)
  12-26 02:34:20.240: E/AndroidRuntime(1734):     at android.os.Looper.loop(Looper.java:137)
  12-26 02:34:20.240: E/AndroidRuntime(1734):     at android.app.ActivityThread.main(ActivityThread.java:5103)
  12-26 02:34:20.240: E/AndroidRuntime(1734):     at java.lang.reflect.Method.invokeNative(Native Method)
  12-26 02:34:20.240: E/AndroidRuntime(1734):     at java.lang.reflect.Method.invoke(Method.java:525)
  12-26 02:34:20.240: E/AndroidRuntime(1734):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
  12-26 02:34:20.240: E/AndroidRuntime(1734):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
  12-26 02:34:20.240: E/AndroidRuntime(1734):     at dalvik.system.NativeStart.main(Native Method)
  12-26 02:34:20.240: E/AndroidRuntime(1734): Caused by: java.lang.NullPointerException
  12-26 02:34:20.240: E/AndroidRuntime(1734):     at com.testing.mypractise.AndroidXMLParsingActivity.onCreate(AndroidXMLParsingActivity.java:55)
  12-26 02:34:20.240: E/AndroidRuntime(1734):     at android.app.Activity.performCreate(Activity.java:5133)
  12-26 02:34:20.240: E/AndroidRuntime(1734):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
  12-26 02:34:20.240: E/AndroidRuntime(1734):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2175)
  12-26 02:34:20.240: E/AndroidRuntime(1734):     ... 11 more
  </code></pre>
  
  <p>AndroidXmlParsingActivity:</p>
  
  <pre><code>public class AndroidXMLParsingActivity extends ListActivity {
  
      // All static variables
      static final String URL = "http://....../.../Images/testing.xml";
      // XML node keys
      static final String KEY_ITEM = "item"; // parent node
      static final String KEY_CATEGORY = "category";
      static final String KEY_CHANNELNAME = "channelname";
      //Intent imgvw;
  
      @Override
      public void onCreate(Bundle savedInstanceState) {
  
          StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
          StrictMode.setThreadPolicy(policy);
          super.onCreate(savedInstanceState);
          setContentView(R.layout.tv_main);
  
          ArrayList&lt;HashMap&lt;String, String&gt;&gt; channellist = new ArrayList&lt;HashMap&lt;String, String&gt;&gt;();
  
          XMLParser parser = new XMLParser();
          String xml = parser.getXmlFromUrl(URL); 
          Document doc = parser.getDomElement(xml); 
  
          **NodeList nl = doc.getElementsByTagName(KEY_ITEM);**  =&gt; this is 55th line
  
          for (int i = 0; i &lt; nl.getLength(); i++) {
  
              HashMap&lt;String, String&gt; listmap = new HashMap&lt;String, String&gt;();
              Element e = (Element) nl.item(i);
  
              listmap.put(KEY_CATEGORY, parser.getValue(e, KEY_CATEGORY));
              listmap.put(KEY_CHANNELNAME, parser.getValue(e, KEY_CHANNELNAME));
  
              // adding HashList to ArrayList
              channellist.add(listmap);
          }
  
          // Adding menuItems to ListView
          ListAdapter adapter = new SimpleAdapter(this, channellist,
                  R.layout.list_item,
                  new String[] { KEY_CATEGORY, KEY_CHANNELNAME}, new int[] {
                          R.id.category, R.id.cahnnel_name});
  
          setListAdapter(adapter);
  
          // selecting single ListView item
          ListView lv = getListView();
  
          lv.setOnItemClickListener(new OnItemClickListener() {
  
              @Override
              public void onItemClick(AdapterView&lt;?&gt; parent, View view,
                      int position, long id) {
                  // getting values from selected ListItem
                  String category = ((TextView) view.findViewById(R.id.category)).getText().toString();
                  String channelname = ((TextView) view.findViewById(R.id.cahnnel_name)).getText().toString();
  
                  try {
                      ImageView imgvw = (ImageView) findViewById (R.id.image_logo);
                        Bitmap bitmap;
                      bitmap = BitmapFactory.decodeStream((InputStream)new URL("http://192.168.2.57:8080/Iptvtest/Images/bnews1.png").getContent());
                      imgvw.setImageBitmap(bitmap);
                  } 
                  catch (MalformedURLException e) 
                  {
  
                      e.printStackTrace();
                  } 
                  catch (IOException e) 
                  {
  
                      e.printStackTrace();
                  }
  
  
  
                  // Starting new intent
                  Intent in = new Intent(getApplicationContext(), SingleMenuItemActivity.class);
                  in.putExtra(KEY_CATEGORY, category);
                  in.putExtra(KEY_CHANNELNAME, channelname);
                  //in.putExtras(imgvw);
  
                  startActivity(in);
  
              }
          });
      }
  }
  </code></pre>
  
  <p>And am facing this error in <code>getDomElement</code> on xmlparser class:</p>
  
  <pre><code>public class XMLParser {
  
      // constructor
      public XMLParser() {
  
      }
  
      /**
       * Getting XML from URL making HTTP request
       * @param url string
       * */
      public String getXmlFromUrl(String url) {
          String xml = null;
  
          try {
              // defaultHttpClient
              DefaultHttpClient httpClient = new DefaultHttpClient();
              HttpPost httpPost = new HttpPost(url);
  
              HttpResponse httpResponse = httpClient.execute(httpPost);
              HttpEntity httpEntity = httpResponse.getEntity();
              xml = EntityUtils.toString(httpEntity);
  
          } 
          catch (UnsupportedEncodingException e) 
          {
              e.printStackTrace();
          } 
          catch (ClientProtocolException e)
          {
              e.printStackTrace();
          } 
          catch (IOException e) 
          {
              e.printStackTrace();
          }
          // return XML
          return xml;
      }
  
      /**
       * Getting XML DOM element
       * @param XML string
       * */
      public Document getDomElement(String xml){
          Document doc = null;
          DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
          try {
  
              DocumentBuilder db = dbf.newDocumentBuilder();
  
              InputSource is = new InputSource();
                  is.setCharacterStream(new StringReader(xml));  // error here.
                  doc = db.parse(is); 
  
              } 
          catch (ParserConfigurationException e)
          {
                  Log.e("Error: ", e.getMessage());
                  return null;
              } 
          catch (SAXException e) 
          {
                  Log.e("Error: ", e.getMessage());
                  return null;
              } 
          catch (IOException e) 
          {
                  Log.e("Error: ", e.getMessage());
                  return null;
              }
  
              return doc;
      }
  
      /** Getting node value
        * @param elem element
        */
       public final String getElementValue( Node elem ) 
       {
           Node child;
           if( elem != null)
           {
               if (elem.hasChildNodes())
               {
                   for( child = elem.getFirstChild(); child != null; child = child.getNextSibling() )
                   {
                       if( child.getNodeType() == Node.TEXT_NODE  )
                       {
                           return child.getNodeValue();
                       }
                   }
               }
           }
           return "";
       }      
       /**
        * Getting node value
        * @param Element node
        * @param key string
        * */
       public String getValue(Element item, String str) {     
              NodeList n = item.getElementsByTagName(str);        
              return this.getElementValue(n.item(0));
          }
  }
  </code></pre>
  
  <p>and the error is </p>
  
  <pre><code>HTTP Error 405 - The HTTP verb used to access this page is not allowed.&lt;br&gt;Internet Information Services (IIS)
  </code></pre>