title: ArrayOutOfBoundException while parsing a file in java froma local xml file to new text file
body: <pre><code>Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
      at com.demo.parsing.MainActivity.main(MainActivity.java:47)
  </code></pre>
  
  <blockquote>
    <p>Writer out = new FileWriter(new File(args[0])); (line 47)</p>
  </blockquote>
  
  <p>I am new to JAVA. I have been trying this code but not able to find what this <code>arrayoutofboundexception</code>. Here in this code i'm trying to parse some data from a local XML file and write it in a new file. The file is created but no text and getting the above exception</p>
  
  <pre><code>package com.demo.parsing;
  
  import java.io.File;
  import java.io.FileWriter;
  import java.io.IOException;
  import java.io.InputStream;
  import java.io.Writer;
  import java.util.LinkedList;
  import java.util.List;
  
  import javax.xml.parsers.DocumentBuilder;
  import javax.xml.parsers.DocumentBuilderFactory;
  import javax.xml.parsers.ParserConfigurationException;
  
  import org.jsoup.Jsoup;
  import org.w3c.dom.Document;
  import org.w3c.dom.Element;
  import org.w3c.dom.NodeList;
  import org.xml.sax.SAXException;
  public class MainActivity {
  
  //private static OutputStreamWriter out;
  
  
  public static void main(String[] args) throws FileNotFoundException {
      FileInputStream f0 = new FileInputStream("/home/kailash/workspace/paarsing/pustaka-feed.xml");
  
      try {
          DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
  
          Document feed = builder.parse(f0);
  
          NodeList items = feed.getElementsByTagName("item");
  
          List&lt;String&gt; urls = new LinkedList&lt;String&gt;();
  
          for (int i = 0; i &lt; items.getLength(); i++) {
              Element item = (Element) items.item(i);
              Element description = (Element) item.getElementsByTagName(
                      "description").item(0);
              urls.addAll(getImages(builder,    description.getTextContent()));
          }
  
   Writer out = new FileWriter(new File(args[0]));
  
          for (String url : urls) {
              out.write(url + "\n");
          }
  
          out.close();
  
      } catch (ParserConfigurationException e) {
          e.printStackTrace();
      } catch (SAXException e) {
          e.printStackTrace();
      } catch (IOException e) {
          e.printStackTrace();
      }
  
  }
  
  private static List&lt;String&gt; getImages(DocumentBuilder builder, String content) throws SAXException, IOException {
      List&lt;String&gt; urls = new LinkedList&lt;String&gt;();
  
      for (org.jsoup.nodes.Element img :   Jsoup.parse(content).getElementsByTag("img")) {
          urls.add(img.attributes().get("src"));
      }
  
      return urls;
  }
  }
  </code></pre>