Error: can only iterate through an array or an instance of java.lang.Iterable
It clearly states that you should iterate only objects that are iterable.
In your code you use
NodeCollection<Shape> shapes = doc.getChildNodes(NodeType.SHAPE, true, false); ... for(Shape shape: shapes)
The for loop fails if the shapes base class is not an instance of java.util.Collection or java.lang.Iterable .
Check if the NodeCollection a collection type class that implemented java.lang.Iterable .
Edit :
nodeCollection - from com.aspose.words.
NodeCollection implements a generic Iterable directly, without specifying the type of objects it will process. Therefore, you must explicitly generate an Iterator from the NodeCollection instance and that you can iterate.
NodeCollection<Shape> shapes = doc.getChildNodes(NodeType.SHAPE, true, false); Iterator<Shape> shapesIterator = shapes.iterator(); ... // now use the above iterator in for loop, as below for( Shape shape: shapesIterator )
Refer to a similar answer to .
source share