Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8775433
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T18:47:51+00:00 2026-06-13T18:47:51+00:00

Exception in thread main java.lang.ArrayIndexOutOfBoundsException: 0 at com.demo.parsing.MainActivity.main(MainActivity.java:47) Writer out = new FileWriter(new File(args[0]));

  • 0
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
    at com.demo.parsing.MainActivity.main(MainActivity.java:47)

Writer out = new FileWriter(new File(args[0])); (line 47)

I am new to JAVA. I have been trying this code but not able to find what this arrayoutofboundexception. 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

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<String> urls = new LinkedList<String>();

        for (int i = 0; i < 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<String> getImages(DocumentBuilder builder, String content) throws SAXException, IOException {
    List<String> urls = new LinkedList<String>();

    for (org.jsoup.nodes.Element img :   Jsoup.parse(content).getElementsByTag("img")) {
        urls.add(img.attributes().get("src"));
    }

    return urls;
}
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T18:47:52+00:00Added an answer on June 13, 2026 at 6:47 pm

    As you say you are newbie and dont know what ArrayIndexOutOfBoundsException is, Better read about ArrayIndexOutOfBoundsException , as this is one the most common exception you are going to face in future.

    Now about your question, it is throwing a ArrayIndexOutOfBoundsException at line 47

    As you point out , Line 47 is

        Writer out = new FileWriter(new File(args[0]));
    

    See the exception trace carefully

    Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
        at com.demo.parsing.MainActivity.main(MainActivity.java:47)
    

    The trace tells you

    1. the exception : ArrayIndexOutOfBoundsException
    2. idex at which this exception occurs : 0
    3. line that is throwing the exception : MainActivity.java : 47 (that is why i asked what is line 47)

    ^telling above info as you are a newbie and this description might be helpful for you in near future.

    So now comming back to your statement

    Writer out = new FileWriter(new File(args[0]));
    

    args[0] , it represents the command line arguments (see main method definition)

    are you passing any command line arguments, when you are trying to run the application ?

    To pass command line arguments

    Through DOS : java nameofclassfile arg1 arg2 ......

    Through Eclipse : right click java file -> run as-run configurations, in the dialog navigate to Arguments tab and enter your command line argument under the Program Arguments text Box and hit run

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am getting Exception in thread main java.lang.ArrayIndexOutOfBoundsException: 0 at com.ibm.icu.text.BreakDictionary.main(BreakDictionary.java:40) When I run/debug
Error:Exception in thread main java.lang.NullPointerException at com.vipgamming.Frytree.Game.main(Game.java:47) I am not a very good programmer.
I get this exception: Exception in thread main java.lang.ArrayIndexOutOfBoundsException: 100 at Vindu.<init>(setevelger.java:64) at setevelger.main(setevelger.java:22)
Exception in thread main java.lang.NullPointerException at com.hibernate.UserDAO.findAll(UserDAO.java:154) at test.main(test.java:12) I am getting this error
Exception in thread main java.lang.ArrayIndexOutOfBoundsException: -1 i have an array of boolean type which
Exception in thread Main java.lang.UnsatisfiedLinkError: com.sun.midp.main.Configuration.getProperty0 (Ljava / lang / String;) Ljava / lang
Exception in thread main java.lang.NullPointerException at Library.loadBooks(Library.java:179) at UseLibrary.main(UseLibrary.java:105) This error makes me crazy!
if I run java -classpath ./sqljdbc4.jar myclassname error is Exception in thread main java.lang.NoClassDefFoundError:myclassname
I'm having a problem where I receive this error: Exception in thread main java.lang.NullPointerException
Exception in thread main java.lang.ExceptionInInitializerError at org.apache.tools.ant.util.FileUtils.<clinit>(FileUtils.java:63) at org.apache.tools.ant.Project.<clinit>(Project.java:131) at Pv.plugin_execute(Pv.java:140) at Pv.main(Pv.java:194) Caused

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.