Results 1 to 10 of 10

Thread: Error

  1. #1
    jayapratha is offline Member
    Join Date
    Jul 2011
    Posts
    6
    Rep Power
    0

    Unhappy Error

    Hi,
    can any one clear my query,


    public static void main(String args[])
    {
    int a=Integer.parseInt(args[0]);
    int b=Integer.parseInt(args[1]);
    int c=a+b;
    System.out.println("Added Value is:" + c);
    }


    I get the error like this:
    i dont ve a clear idea abt arrayindexoutofexception.

    Exception in thread "main" java.lang.Error: Unresolved compilation problem:
    Syntax error on tokens, delete these tokens

    at add.main(add.java:9)

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,423
    Rep Power
    20

    Default

    How did you run the program? Is that the entire code?

    db

  3. #3
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,578
    Rep Power
    25

    Default

    arrayindexoutofexception.
    For example if the array has 2 elements and your code tries to look at the 3rd element, that index would be out of bounds.
    Or in your case, if the array has 0 elements and the code tries to look at the first element (index = 0)

    When posting error messages please copy and paste the FULL text of the error message.

  4. #4
    jayapratha is offline Member
    Join Date
    Jul 2011
    Posts
    6
    Rep Power
    0

    Default

    This is the error:

    Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 1
    at add.main(add.java:8)

  5. #5
    jayapratha is offline Member
    Join Date
    Jul 2011
    Posts
    6
    Rep Power
    0

    Default

    I am using eclipse environment... just directly run the program..

  6. #6
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,798
    Rep Power
    7

    Default

    You need to pass 2 command line arguments to your program. You can do this in Eclipse by modifying the properties of the project.

  7. #7
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,423
    Rep Power
    20

    Default

    Did you pass the parameters that the main(...) method expects to parse?
    Command-Line Arguments (The Java™ Tutorials > Essential Classes > The Platform Environment)

    db

  8. #8
    jayapratha is offline Member
    Join Date
    Jul 2011
    Posts
    6
    Rep Power
    0

    Default

    can u pl explain clearly.
    I dnt know how can i clear the error here..
    Thanks in advance...

  9. #9
    jayapratha is offline Member
    Join Date
    Jul 2011
    Posts
    6
    Rep Power
    0

    Default

    yes this is the entire code...

  10. #10
    jayapratha is offline Member
    Join Date
    Jul 2011
    Posts
    6
    Rep Power
    0

Similar Threads

  1. java out of memory error-heap space error
    By elsanthosh in forum NetBeans
    Replies: 4
    Last Post: 06-15-2010, 09:31 AM
  2. Replies: 1
    Last Post: 03-10-2010, 01:53 PM
  3. Replies: 1
    Last Post: 12-05-2009, 07:28 AM
  4. Replies: 1
    Last Post: 10-26-2009, 04:38 PM
  5. Replies: 3
    Last Post: 01-23-2009, 08:53 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
  •