Kotlin / anko

Pleasant Android application development
Apache License 2.0
15.88k stars 1.29k forks source link

NoSuchElementException when attempting to iterate over views #335

Open mvysny opened 7 years ago

mvysny commented 7 years ago

A very simple for loop (currently in Java, not yet converted to Kotlin, I apologize :-) ):

for (Iterator<View> i = ViewChildrenSequencesKt.childrenRecursiveSequence(KViewsKt.getRoot(fm)).iterator(); i.hasNext(); ) {
            final View view = i.next();
}

(the getRoot() looks like this:

val Activity.root: View get() = findViewById(android.R.id.content)!!

fails with

java.util.NoSuchElementException
at org.jetbrains.anko.ViewChildrenRecursiveSequence$RecursiveViewIterator.next(viewChildrenSequences.kt:128)
at org.jetbrains.anko.ViewChildrenRecursiveSequence$RecursiveViewIterator.next(viewChildrenSequences.kt:122)

This is for Anko 0.9

mvysny commented 7 years ago

Also reproducible with Anko 0.9.1a:

java.util.NoSuchElementException
at org.jetbrains.anko.ViewChildrenRecursiveSequence$RecursiveViewIterator.next(viewChildrenSequences.kt:129)
at org.jetbrains.anko.ViewChildrenRecursiveSequence$RecursiveViewIterator.next(viewChildrenSequences.kt:123)
semenoh commented 7 years ago

same issue