Results 1 to 4 of 4
  1. #1
    bibek is offline Member
    Join Date
    Apr 2014
    Posts
    2
    Rep Power
    0

    Default beginig prog in java, error java.lang.arrayIndexOutOfBoundException

    Input a number from user and display it.

    class New
    {
    public static void main(String args[])
    {
    int n1=Integer.parseInt(args[0]);
    int n2=Integer.parseInt(args[1]);
    System.out.println(n1);
    System.out.println(n2);
    }
    }

  2. #2
    kneitzel is offline Senior Member
    Join Date
    Feb 2014
    Posts
    447
    Rep Power
    1

    Default Re: beginig prog in java, error java.lang.arrayIndexOutOfBoundException

    Hi,

    You used the commandline arguments in your code and not user input.

    And if you do not hand over arguments, you will get the given error.

    Maybe you want to have a closer look at the Scanner class?

    With kind regards,

    Konrad

  3. #3
    bibek is offline Member
    Join Date
    Apr 2014
    Posts
    2
    Rep Power
    0

    Default Re: beginig prog in java, error java.lang.arrayIndexOutOfBoundException

    Thank you for the reply will surely look into the scanner class

    bibek

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

    Default Re: beginig prog in java, error java.lang.arrayIndexOutOfBoundException

    Quote Originally Posted by bibek View Post
    Thank you for the reply will surely look into the scanner class
    That 'unsolves' your problem; you might have a look at the JTable class API documentation as well; now your code throws that exception because you didn't supply two command line arguments and your code demands them; your question surprises me if you have written that code snippet yourself, because you could (and would) have known that little fact ...

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. Replies: 5
    Last Post: 07-25-2012, 04:11 PM
  2. Replies: 12
    Last Post: 09-23-2011, 01:25 PM
  3. Replies: 3
    Last Post: 05-02-2011, 07:51 AM
  4. Replies: 5
    Last Post: 08-13-2010, 10:04 AM
  5. Replies: 2
    Last Post: 09-18-2008, 07:30 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
  •