ArrayIndexOutOfBounds exception comes when your size of array is less than your iteration for example
if size of your array is 5 and your trying to access 6th element of array which is not feasible then such kind of exception comes
in your case
i think length of JSONArray.length is the issue please check this through debugger
thats why such kind of exception is coming for your code