我正在使用 Recycler View 并在 Android Studio 中运行测试文件。
但是当测试文件到达此行时我收到错误
onView(ViewMatchers.withId(R.id.itemList)).perform(RecyclerViewActions.scrollTo(withText("And a large, silver "+choice2)));
显示的错误是
androidx.test.espresso.PerformException: Error performing 'scroll RecyclerView to: holder with view: with text: is "And a large, silver CAT"' on view 'with id is cs.bham.ac.uk.wk12lh:id/itemList'. Caused by: java.lang.RuntimeException: Found 0 items matching holder with view: with text: is "And a large, silver CAT", but position -1 was requested.
请指导我做错了什么或如何做对。
最佳答案
从此改变
onView(ViewMatchers.withId(R.id.itemList)).perform(RecyclerViewActions.scrollTo(withText("And a large, silver "+choice2)));
到此
onView(ViewMatchers.withId(R.id.itemList))
.perform(RecyclerViewActions.scrollTo(hasDescendant(withText("And a large, silver "+choice2))));
关于android - 执行“滚动 RecyclerView 到 : holder with view: with text:--Getting error in Android Studio”时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67549255/