Results 1 to 2 of 2
  1. #1
    Join Date
    Nov 2009
    Posts
    1
    Rep Power
    0

    Default Runtime error "Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0

    Hi All,

    I am new to Java, I have written a program where i am getting the error

    Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0

    here is the code.

    import java.net.URL;
    import java.io.*;
    import org.w3c.tidy.Tidy;

    public class TestHTML2XML {
    private String url;
    private String outFileName;
    private String errOutFileName;

    public TestHTML2XML(String url, String outFileName, String
    errOutFileName) {
    this.url = url;
    this.outFileName = outFileName;
    this.errOutFileName = errOutFileName;
    }

    public void convert() {
    URL u;
    BufferedInputStream in;
    FileOutputStream out;

    Tidy tidy = new Tidy();

    //Tell Tidy to convert HTML to XML
    tidy.setXmlOut(true);

    try {
    //Set file for error messages
    tidy.setErrout(new PrintWriter(new FileWriter(errOutFileName), true));
    u = new URL(url);

    //Create input and output streams
    in = new BufferedInputStream(u.openStream());
    out = new FileOutputStream(outFileName);

    //Convert files
    tidy.parse(in, out);

    //Clean up
    in.close();
    out.close();

    } catch (IOException e) {
    System.out.println(this.toString() + e.toString());
    }
    }

    public static void main(String[] args) {
    /*
    * Parameters are:
    * URL of HTML file
    * Filename of output file
    * Filename of error file
    */
    System.out.println("url" + args[0]);
    System.out.println("abc.xml" + args[1]);
    System.out.println("123.xml" + args[2]);
    TestHTML2XML t = new TestHTML2XML(args[0], args[1], args[2]);
    t.convert();
    }
    }


    Please help me out where i am doing wrong.

    thanks in advance.

  2. #2
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,778
    Blog Entries
    7
    Rep Power
    21

    Default

    My guess: you're not passing any parameters to your main( ... ) method.

    kind regards,

    Jos

    ps. the exception also tells you exactly where the error happened; look there.

Similar Threads

  1. Replies: 8
    Last Post: 03-05-2011, 04:53 AM
  2. Replies: 6
    Last Post: 07-16-2009, 04:30 PM
  3. Replies: 1
    Last Post: 07-16-2009, 11:35 AM
  4. Replies: 1
    Last Post: 08-07-2007, 08:10 AM
  5. Replies: 1
    Last Post: 07-25-2007, 11:55 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •