android - 执行“滚动 RecyclerView 到 : holder with view: with text:--Getting error in Android Studio”时出错

标签 android android-studio android-recyclerview

我正在使用 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/

相关文章:

Android studio 4.0 新更新版本说 Kotlin 与这个新版本不兼容

java - 显示指定文件夹中的视频列表

android - 应用程序图标不显示 (Android Studio)

java - 布局小不被识别/不工作

java - RecyclerView Onclick(调用非静态方法)

javascript - Android - 检查元素是否存在于 WebView 中(在 DOM 中)

android - 按下按钮时如何在 Activity 中绘制垂直线?

android - 水平回收器 View 不显示任何内容

android - 在 Ubuntu 14.10 中从 Android Studio 启动 Android Device Monitor

android - RecyclerView 不会显示数据