Doubt related to null pointer exception

Hello, I wanted to know why did you define the “indices[ ]” array as null initially. And I think due to this I am getting error for Null Pointer exception as given below,

Exception in thread “main” java.lang.NullPointerException: Cannot store to int array because “indices” is null

Without initializing an array you cannot store any value in that array.please share your code there must be some other error
we are assigning count length to array as we haven’t initialized the indices array coz we dont know the size
so we r counting first how many elements are there and returning the array after initializing that with required size.it should not give any error