From java:

onView(withId(R.id.recyclerView)).perform(RecyclerViewActions.scrollTo(
    hasDescendant(withText(artistResult.getNameVariations().get(0)))));

Trying to convert to Kotlin:

onView(withId(R.id.recyclerView)).perform(RecyclerViewActions.scrollTo(
    hasDescendant(withText(artistResult.nameVariations[0]))))

我得到了这个堆栈跟踪:

Error:(63, 71) Type inference failed: Not enough information to infer parameter VH in fun <VH : RecyclerView.ViewHolder!> scrollTo(itemViewMatcher: Matcher<View!>!): RecyclerViewActions.PositionableRecyclerViewAction!
Please specify it explicitly.

I'm not entirely sure where I can specify "it" explicitly. When this has come up previously it's because I didn't initialise the value correctly, but here I'm calling a method. Any ideas?

推荐答案

我需要把<RecyclerView.ViewHolder>加到scrollTo

onView(withId(R.id.recyclerView)).perform(
    RecyclerViewActions.scrollTo<RecyclerView.ViewHolder>(
    hasDescendant(withText(artistResult.nameVariations[0]))))

Kotlin相关问答推荐

Microronaut Data 4和JDbi

Kotlin:有限的并行性并不是限制并行性

我需要后台工作才能使用卡夫卡的消息吗?

如何检测一个值是否是Kotlin中的枚举实例?

合并状态流

TzdbZoneRulesProvider 在 java.time 中不工作

如何在 Jetpack Compose 中启动和停止动画

JetPack Compose:添加点击持续时间

验证构造函数中的值组合

在 APK META-INF/library_release.kotlin_module 中复制的重复文件

有没有办法重用 Job 实例?

Kotlin 代码是如何编译成原生代码的?

将 Kotlin 类属性设置器作为函数引用

Kotlin 解构超过五个组件

DatabaseManager_Impl 不是抽象的,不会覆盖 RoomDatabase 中的抽象方法 clearAllTables()

防止导航到同一个片段

Kotlin 中的内联构造函数是什么?

如何使用协调器布局和行为在CardView上完成此动画?

Kotlin 错误:public function exposes its 'public/*package*/' return type argument

Android Jetpack Compose - 图像无法zoom 到框的宽度和高度