java.lang.ArrayIndexOutOfBoundsException: length=4; index=4 length array

后端 未结 2 1311
死守一世寂寞
死守一世寂寞 2020-12-11 18:03

i have this error:

04-02 11:03:57.922: E/AndroidRuntime(18952): FATAL EXCEPTION: main
04-02 11:03:57.922: E/AndroidRuntime(18952): java.lang.ArrayIndexOutOfB         


        
2条回答
  •  天涯浪人
    2020-12-11 18:27

    problem is your array may declared to have only 4 rooms, that means you can access maximum index of 3 but in above code you gonna access 4th index, then it will complain that your index bound in out,your lenth is 4,

    you should use ArrayList instead of array,because Array can't be resize after declaration, but you can add any number of objects to arraylist.

    ArrayList lista=new ArrayList();
    
        

    提交回复
    热议问题