Results 1 to 8 of 8
  1. #1
    rocker is offline Member
    Join Date
    Sep 2010
    Posts
    1
    Rep Power
    0

    Post ArrayIndexOutOfBoundException

    Hi,
    I am new to java.
    I have written a java program just to check the working of different if statements. The code is as follows:


    public class DifferentIfTest{
    public static void main(String[]s){
    //Collect the Course Code
    int courseCode = new Integer( s[0] );
    if( courseCode < 10 ){
    System.out.println( " Science Subjects " );
    if( courseCode == 1 ){
    System.out.println( " Physics " );
    }
    else if( courseCode == 2 ){
    System.out.println( " Chemistry " );
    }
    else if( courseCode == 3 ){
    System.out.println( " Mathematics " );
    }
    else if( courseCode == 4 ){
    System.out.println( " Zoology " );
    }
    else if( courseCode == 5 ){
    System.out.println( " Botany " );
    }
    else if( courseCode == 6 ){
    System.out.println( " C Programming " );
    }
    else{
    System.out.println( " These are science subjects. " );
    }
    }
    else{
    System.out.println( " Commerce Subjects " );
    }
    if( courseCode == 11 ){
    System.out.println( " Economics " );
    }
    else if( courseCode == 12 ){
    System.out.println( " Microeconomics " );
    }
    else if( courseCode == 13 ){
    System.out.println( " Accountancy " );
    }
    else{
    System.out.println( " These are commerce subjects. " );
    }
    }//main
    }//class


    This code compiled successfully but when I run the program the following message appeared on the command prompt

    "java DifferentIfTest
    Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException:
    at DifferentIfTest.main(DifferentIfTest.java:4)"

    I am not understanding what does it mean. Please tell me is there anything wrong in the code I have written.
    Please help me.........
    Thank You.

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

    Default

    Your classmate started an identical thread; same Exception, same classname, even the same line number.

    kind regards,

    Jos

  3. #3
    nitishjtm is offline Member
    Join Date
    Sep 2010
    Posts
    30
    Rep Power
    0

    Post ArrayIndexOutOfBoundException

    Hey Joash, that's my account. I forgot the password of this account that's why posted code from different one. Please tell me is there anything wrong in the code.

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,006
    Rep Power
    20

    Default

    How are you running this?
    Because if you aren't supplying any arguments then "s[0]" will be what's giving you your error.

  5. #5
    georgemc is offline Senior Member
    Join Date
    Sep 2008
    Posts
    135
    Rep Power
    0

    Default

    You're not passing any arguments when you start the app up.

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

    Default

    Quote Originally Posted by nitishjtm View Post
    Hey Joash, that's my account. I forgot the password of this account that's why posted code from different one. Please tell me is there anything wrong in the code.
    Now you know your password of the 'nitishjtm' account again ... and you started this 'rocker' thread after you started your other thread ... on topic: what Tolls said.

    kind regards,

    Jos

  7. #7
    nitishjtm is offline Member
    Join Date
    Sep 2010
    Posts
    30
    Rep Power
    0

    Default ArrayIndexOutOfBoundException

    Thanks, now its working.
    Sir,
    Is there any source from where I can get description about common errors.

  8. #8
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,006
    Rep Power
    20

    Default

    Learn how Java works?
    That one is a pretty basic mistake, and usually implies not understanding how a Java program is launched (ie often occurs when using an IDE to run something that was written with a command line in mind).

Similar Threads

  1. ArrayIndexOutOfBoundException
    By nitishjtm in forum New To Java
    Replies: 3
    Last Post: 09-08-2010, 12:14 AM

Posting Permissions

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