Results 1 to 3 of 3
  1. #1
    Yakg is offline Member
    Join Date
    Dec 2010
    Posts
    59
    Rep Power
    0

    Default ArrayIndexOutOfBoundsException: 10 ??

    hey, I'm receiving this message not for the first time in my program, could you tell me why this is happening and how to fix it?

    Here's the method

    public String toString(){
    int i;
    for (i=1; i<MAX && _points[i] !=null; i++);
    return ("The polygon has 5 points: " +"("+ _vertices[i].toString() +")");

    }

    //thanks.

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

    Default

    Quote Originally Posted by Yakg View Post
    hey, I'm receiving this message not for the first time in my program, could you tell me why this is happening and how to fix it?

    Here's the method

    public String toString(){
    int i;
    for (i=1; i<MAX && _points[i] !=null; i++);
    return ("The polygon has 5 points: " +"("+ _vertices[i].toString() +")");

    }

    //thanks.
    Suppose none of the _points are null; the loop can only terminate when i == MAX; is the value MAX a valid index value in the _vertices array?

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    bigvanilla is offline Member
    Join Date
    Dec 2010
    Posts
    8
    Rep Power
    0

    Default

    Doesnt your array starts with 0 and not 1.

    Java Code:
    public String toString(){
    int i;
    for ([B][COLOR="Red"]i=1[/COLOR][/B]; i<MAX && _points[i] !=null; i++); 
    return ("The polygon has 5 points: " +"("+ _vertices[i].toString() +")");
    
    }

Similar Threads

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