Results 1 to 4 of 4
  1. #1
    mxsar is offline Member
    Join Date
    Nov 2010
    Posts
    4
    Rep Power
    0

    Default ArrayIndexOutOfBoundsException: 0

    Hello all!
    I have started taking classes in Java some weeks ago and I have come across my first problem... I'm getting this error when I run the programme although during the compiling I have no errors. I'm posting the code and the error so maybe someone can help :confused:
    Thank you in advance for your time!

    import java.io.*;
    class AthroismaApp
    { public static void main(String args[]) throws IOException
    { int a, b;
    a=Integer.parseInt(args[0]);
    b=Integer.parseInt(args[1]);
    System.out.println();
    System.out.print("To athroisma ton "+a+" kai "+b);
    System.out.println(" einai iso me "+(a+b));
    }
    }


    Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
    at AthroismaApp.main(AthroismaApp.java:5)

  2. #2
    m00nchile is offline Senior Member
    Join Date
    Feb 2010
    Location
    Ljubljana, Slovenia
    Posts
    470
    Rep Power
    5

    Default

    Do you know what the args array is? How do you start your application? One hint, the args array holds the arguments when you call your program, eg:
    Java Code:
    java MyApp 1 2 3 4
    in the above example, args[0] is 1, args[1] is 2... etc.
    Also another tip, whenever you're doing something with command line arguments, check the length of the args array, to see if it conforms to your demands before you use it in your code.
    Ever seen a dog chase its tail? Now that's an infinite loop.

  3. #3
    mxsar is offline Member
    Join Date
    Nov 2010
    Posts
    4
    Rep Power
    0

    Default

    I got it! We have never used java name parameters before so I didn't know I could put parameters there.

    Thank you very much!!! :D

  4. #4
    m00nchile is offline Senior Member
    Join Date
    Feb 2010
    Location
    Ljubljana, Slovenia
    Posts
    470
    Rep Power
    5

    Default

    No problem, glad I could help.
    Ever seen a dog chase its tail? Now that's an infinite loop.

Similar Threads

  1. ArrayIndexOutOfBoundsException
    By Corey in forum New To Java
    Replies: 5
    Last Post: 02-02-2010, 01:25 AM
  2. ArrayIndexOutOfBoundsException
    By flaskvacuum in forum New To Java
    Replies: 6
    Last Post: 07-14-2009, 05:36 PM
  3. ArrayIndexOutofBoundsException help
    By filly444 in forum New To Java
    Replies: 9
    Last Post: 09-03-2008, 05:16 PM
  4. ArrayIndexOutOfBoundsException
    By daredavil82 in forum New To Java
    Replies: 2
    Last Post: 12-14-2007, 09:29 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
  •