执行 'scroll RecyclerView to:holder with view: with text: 时出错:--在 Android Studio 中出现错误

Mal*_*lik 2 android android-studio android-recyclerview

我正在使用 Recycler View 并在 Android Studio 中运行测试文件。

但是当测试文件到达此行时我收到错误

        onView(ViewMatchers.withId(R.id.itemList)).perform(RecyclerViewActions.scrollTo(withText("And a large, silver "+choice2)));
Run Code Online (Sandbox Code Playgroud)

显示的错误是

androidx.test.espresso.PerformException:执行“将 RecyclerView 滚动到:带有视图的持有者:带有文本:视图上是“和一只大的银色猫”时出错,id 是 cs.bham.ac.uk.wk12lh:id/项目列表'。引起原因:java.lang.RuntimeException:找到 0 个与 view: with text: is “And a Large, silver CAT”相匹配的 Holder 项目,但请求了位置 -1。

请指导我做错了什么或如何做对。

小智 5

从此改变

 onView(ViewMatchers.withId(R.id.itemList)).perform(RecyclerViewActions.scrollTo(withText("And a large, silver "+choice2)));
Run Code Online (Sandbox Code Playgroud)

对此

onView(ViewMatchers.withId(R.id.itemList))
    .perform(RecyclerViewActions.scrollTo(hasDescendant(withText("And a large, silver "+choice2))));
Run Code Online (Sandbox Code Playgroud)