How using these libraries

import com.badlogic.gdx.utils.Array; import java.util.Iterator; 

Go through the elements of this list with a nested loop (Associate objects each with each)

 Array<MyObject> objects; 

Tried to do

 While(iteratorA.hasNext()) { ... While(iteratorB.hasNext()){ ... } } 

But it gives an error:

Exception in thread "LWJGL Application" com.badlogic.gdx.utils.GdxRuntimeException: #iterator () cannot be used nested.

  • github.com/libgdx/ashley/issues/209 looks like your mistake - Artem Konovalov
  • Why do you use a third-party library? Why not ArrayList, LinkedList etc. - GVArt
  • @GVArt because gdx counterparts work faster than the built-in javovskie - lapots

1 answer 1

That's because Array.iterator () returns the same object every time. And in order to iterate over the same array when you are already iterating over it (ie, while in while), you need to use the ArrayIterator as suggested by the Array.iterator () documentation.

This is done so that each time you iterate the array, you do not create a new object. Therefore, I recommend using Array.iterator () for the inner loop, and ArrayIterator for the outer loop. Or store an iterator and reset it every time.