What does this JAVA exception mean?

Discussion in 'Programming' started by Black Fire, Jan 22, 2010.

  1. #1
    I have no idea what it means.
     
    Black Fire, Jan 22, 2010 IP
  2. RDJLabs

    RDJLabs Peon

    Messages:
    170
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Arrayindexoutofbound exception comes in the picture when you are using element of the array and you have not any elements in the array. So make sure that you are having array before using it.
     
    RDJLabs, Jan 22, 2010 IP
  3. segzeey

    segzeey Active Member

    Messages:
    350
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    78
    #3
    e.g

    String h = new String[1];
    h[0] = 'my';

    String g = new String[10];

    if you try to access h[2] or g[0] you will get that exception.
     
    segzeey, Jan 22, 2010 IP
  4. Black Fire

    Black Fire Well-Known Member

    Messages:
    804
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    130
    #4
    Fixed.......
     
    Last edited: Jan 22, 2010
    Black Fire, Jan 22, 2010 IP
  5. Black Fire

    Black Fire Well-Known Member

    Messages:
    804
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    130
    #5
    Also, please explain what I am doing wrong (if you can help me), I really would like to learn from this.
     
    Black Fire, Jan 22, 2010 IP
  6. Black Fire

    Black Fire Well-Known Member

    Messages:
    804
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    130
    #6
    I'll pay $12 to whoever can help me fix this problem.
     
    Black Fire, Jan 22, 2010 IP
  7. hhelen

    hhelen Member

    Messages:
    352
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    33
    #7
    It is hard to explain beyond what someone else has explained above without seeing your code. If possible, post it on pastebin and link to it.
     
    hhelen, Jan 22, 2010 IP
  8. mastermunj

    mastermunj Well-Known Member

    Messages:
    687
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    110
    #8
    Following is the explanation:

    First line means, that you have an array containing total 10 elements but you tried to access 11th [array accessed from 0] which is not available and hence "index out of boundary".
    From second line starts the error stack trace, which means, all the execution point where the error got propagated without being caught. Error began at Screen.java file on line 32. A function call to (draw) Screen.java was made from Menu.java on line 105.

    All you need to do here is following:
    1. If you are using a for or while loop, make sure the limits of loop are set proper.
    e.g. if array length is 10, you can use it as for(int i = 0; i < array.length; i++).
    2. If its direct access, then make sure either the data is coming proper OR keep a check of length of array before accessing random index out of it.

    Hope above explanation helps a little at least :)
     
    mastermunj, Jan 22, 2010 IP