Results 1 to 7 of 7
  1. #1
    jhasaroj is offline Member
    Join Date
    Aug 2012
    Location
    Bangalore
    Posts
    3
    Rep Power
    0

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

    Hi,

    Could you please help me to resolve this issue?

    while running this below program, i am getting this error message:

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

    This is the program:

    import java.io.*;

    class Rev
    {
    public static void main(String as[])
    {
    int n = Integer.parseInt(as[0]);
    int c = 0;
    int rev = 0;
    int m = n;
    int r = 0;
    while(n!=0)
    {
    r = n%10;
    rev = rev*10+r;
    n = n/10;
    c++;
    }
    System.out.println(c);
    System.out.println("Reverse of" +m+ "is" +rev);
    if(m==rev)
    {
    System.out.println(m+"is palindrome");
    }
    else
    {
    System.out.println(m+"is not palindrome");
    }
    }
    }

    Thanks,

    Saroj

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,534
    Blog Entries
    7
    Rep Power
    20

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

    Your program expects (at least) one command line argument (see the first line in your main( ... ) method) but you didn't supply any. You did write this code yourself, did you?

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    jhasaroj is offline Member
    Join Date
    Aug 2012
    Location
    Bangalore
    Posts
    3
    Rep Power
    0

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

    Quote Originally Posted by JosAH View Post
    Your program expects (at least) one command line argument (see the first line in your main( ... ) method) but you didn't supply any. You did write this code yourself, did you?

    kind regards,

    Jos
    Thanks Jos for replying....

    where should i supply? yes, i hv written this pgm?

    Thanks,


    Saroj

  4. #4
    Join Date
    May 2013
    Posts
    2
    Rep Power
    0

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

    if you run this program in eclipse
    right click on the java file->go to run configuration->verify the project you specified and the class name in main tab are correct -> go to arguments and supply any number like 1234
    where your output will be 4321

  5. #5
    jhasaroj is offline Member
    Join Date
    Aug 2012
    Location
    Bangalore
    Posts
    3
    Rep Power
    0

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

    i am running this program thru cmd prompt.

  6. #6
    Join Date
    May 2013
    Posts
    2
    Rep Power
    0

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

    run like this
    java class_name arguments
    java Rev 1234

  7. #7
    allaudin's Avatar
    allaudin is offline Senior Member
    Join Date
    Apr 2013
    Posts
    271
    Rep Power
    0

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

    run it like if you are running jar file
    java -jar name.jar arguments ....

Similar Threads

  1. Replies: 6
    Last Post: 04-27-2012, 12:37 AM
  2. Replies: 4
    Last Post: 01-04-2012, 11:23 PM
  3. Replies: 3
    Last Post: 10-20-2011, 04:58 PM
  4. Replies: 1
    Last Post: 11-20-2009, 07:58 PM
  5. Replies: 1
    Last Post: 07-25-2007, 10: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
  •